| author | |
| committer | |
| log | e48e707c32121a73f1fd2862197c8f47dbceea5e |
| tree | 169957347234a697928c24f5a56d0b7044ce12f6 |
| parent | a7f77d7c6a4326de4c4cd356cd88e48854817e6f |
closes #6233 files changed, 19 insertions(+), 2 deletions(-)
src/ir.cpp+8-1| ... | @@ -11804,7 +11804,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -11804,7 +11804,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 11804 | } | 11804 | } |
| 11805 | } | 11805 | } |
| 11806 | 11806 | ||
| 11807 | bool comptime_arg = param_decl_node->data.param_decl.is_inline; | 11807 | bool comptime_arg = param_decl_node->data.param_decl.is_inline || |
| 11808 | casted_arg->value.type->id == TypeTableEntryIdNumLitInt || casted_arg->value.type->id == TypeTableEntryIdNumLitFloat; | ||
| 11808 | 11809 | ||
| 11809 | ConstExprValue *arg_val; | 11810 | ConstExprValue *arg_val; |
| 11810 | 11811 | ||
| ... | @@ -11829,6 +11830,12 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod | ... | @@ -11829,6 +11830,12 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 11829 | var->shadowable = !comptime_arg; | 11830 | var->shadowable = !comptime_arg; |
| 11830 | 11831 | ||
| 11831 | *next_proto_i += 1; | 11832 | *next_proto_i += 1; |
| 11833 | } else if (casted_arg->value.type->id == TypeTableEntryIdNumLitInt || | ||
| 11834 | casted_arg->value.type->id == TypeTableEntryIdNumLitFloat) | ||
| 11835 | { | ||
| 11836 | ir_add_error(ira, casted_arg, | ||
| 11837 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/zig-lang/zig/issues/557")); | ||
| 11838 | return false; | ||
| 11832 | } | 11839 | } |
| 11833 | 11840 | ||
| 11834 | if (!comptime_arg) { | 11841 | if (!comptime_arg) { |
test/cases/fn.zig+10| ... | @@ -94,3 +94,13 @@ test "inline function call" { | ... | @@ -94,3 +94,13 @@ test "inline function call" { |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | fn add(a: i32, b: i32) i32 { return a + b; } | 96 | fn add(a: i32, b: i32) i32 { return a + b; } |
| 97 | |||
| 98 | |||
| 99 | test "number literal as an argument" { | ||
| 100 | numberLiteralArg(3); | ||
| 101 | comptime numberLiteralArg(3); | ||
| 102 | } | ||
| 103 | |||
| 104 | fn numberLiteralArg(a: var) void { | ||
| 105 | assert(a == 3); | ||
| 106 | } |
test/compile_errors.zig+1-1| ... | @@ -1723,7 +1723,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void { | ... | @@ -1723,7 +1723,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 1723 | \\} | 1723 | \\} |
| 1724 | \\ | 1724 | \\ |
| 1725 | \\export fn entry() usize { return @sizeOf(@typeOf(bar)); } | 1725 | \\export fn entry() usize { return @sizeOf(@typeOf(bar)); } |
| 1726 | , ".tmp_source.zig:10:16: error: parameter of type '(integer literal)' requires comptime"); | 1726 | , ".tmp_source.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted"); |
| 1727 | 1727 | ||
| 1728 | cases.add("assign too big number to u16", | 1728 | cases.add("assign too big number to u16", |
| 1729 | \\export fn foo() void { | 1729 | \\export fn foo() void { |