Repository navigation
Closed
Description
On Zig 0.5.0+d18b5f8b5, with Fedora 30, x86_64.
Here's a program that reproduce the problem (uncomment a declaration to get the compile error on top) :
const MyStruct = struct{
array: Array(u32),
};
fn Array(comptime T: type) type {
return struct{
things: []T,
pub fn init() @This() {
return @This(){
.things = [0]T{},
};
}
};
}
pub fn main() void {
// broken LLVM module found: Call parameter type does not match function signature!
// %0 = getelementptr inbounds %MyStruct, %MyStruct* %s0, i32 0, i32 0, !dbg !14548
// %"Array(u8)"* call fastcc void @"Array(u8).init"(%"Array(u32)"* sret %0), !dbg !14549
var s0 = MyStruct{ .array = Array(u8).init() };
// main.zig:26:59: error: expected type '[]u32', found '[0]u8'
// var s1 = MyStruct{ .array = Array(u8){ .things = [0]u8{} } };
// ^
// var s1 = MyStruct{ .array = Array(u8){ .things = [0]u8{} } };
// Compile with no error
// var s2 = MyStruct{ .array = Array(u8){ .things = [0]u32{} } };
// These ones give the expected compile error message :
// error: expected type 'Array(u32)', found 'Array(u8)'
// var s3: Array(u32) = Array(u8).init();
// error: expected type 'Array(u32)', found 'Array(u8)'
// var s4: Array(u32) = Array(u8){ .things = [0]u8{} };
// error: expected type '[]u8', found '[0]u32'
// var s5: Array(u32) = Array(u8){ .things = [0]u32{} };
}With s0 and s1, the compiler should gives a expected type 'Array(u32)', found 'Array(u8)', but instead it either crashes or give an error on the wrong thing. The Array(u8).init function seems to be compiled with an Array(u32) return type.
s2 should give an error like expected type '[]u8', found '[0]u32 or expected type 'Array(u32)', found 'Array(u8)', but it doesn't. So, it seems to be ignoring the literal's type and using the return location's type instead.
Note that this doesn't happen when the Array(u8) literal is put directly in a variable like with s3, s4, and s5.
Activity
pixelherodev commentedon Dec 8, 2019
An example of this using just zag (and no I'm not going to stop calling the zig standard library zag):
fix not checking type of return pointer