Merge branch 'master' of github.com:zig-lang/zig
commit
ed1b028276
|
@ -11804,7 +11804,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
|
|||
}
|
||||
}
|
||||
|
||||
bool comptime_arg = param_decl_node->data.param_decl.is_inline;
|
||||
bool comptime_arg = param_decl_node->data.param_decl.is_inline ||
|
||||
casted_arg->value.type->id == TypeTableEntryIdNumLitInt || casted_arg->value.type->id == TypeTableEntryIdNumLitFloat;
|
||||
|
||||
ConstExprValue *arg_val;
|
||||
|
||||
|
@ -11829,6 +11830,12 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
|
|||
var->shadowable = !comptime_arg;
|
||||
|
||||
*next_proto_i += 1;
|
||||
} else if (casted_arg->value.type->id == TypeTableEntryIdNumLitInt ||
|
||||
casted_arg->value.type->id == TypeTableEntryIdNumLitFloat)
|
||||
{
|
||||
ir_add_error(ira, casted_arg,
|
||||
buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/zig-lang/zig/issues/557"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!comptime_arg) {
|
||||
|
|
|
@ -94,3 +94,13 @@ test "inline function call" {
|
|||
}
|
||||
|
||||
fn add(a: i32, b: i32) i32 { return a + b; }
|
||||
|
||||
|
||||
test "number literal as an argument" {
|
||||
numberLiteralArg(3);
|
||||
comptime numberLiteralArg(3);
|
||||
}
|
||||
|
||||
fn numberLiteralArg(a: var) void {
|
||||
assert(a == 3);
|
||||
}
|
||||
|
|
|
@ -1723,7 +1723,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
|
|||
\\}
|
||||
\\
|
||||
\\export fn entry() usize { return @sizeOf(@typeOf(bar)); }
|
||||
, ".tmp_source.zig:10:16: error: parameter of type '(integer literal)' requires comptime");
|
||||
, ".tmp_source.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted");
|
||||
|
||||
cases.add("assign too big number to u16",
|
||||
\\export fn foo() void {
|
||||
|
|
Loading…
Reference in New Issue