Merge branch 'master' of github.com:zig-lang/zig

This commit is contained in:
Jimmi Holst Christensen 2018-04-11 20:56:22 +02:00
commit ed1b028276
3 changed files with 19 additions and 2 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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 {