| author | |
| committer | |
| log | ed1b028276bc1d17ee5e99863dd5bf150c8aa2f7 |
| tree | 7fd75a17dc9ca3829f9878c5acb70bcddf3be6a8 |
| parent | 5b584e06e37296c602357cbaf27d39e068ac98c9 |
| parent | e48e707c32121a73f1fd2862197c8f47dbceea5e |
3 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 | 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 | 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 | 11830 | var->shadowable = !comptime_arg; |
| 11830 | 11831 | |
| 11831 | 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 | 11841 | if (!comptime_arg) { |
test/cases/fn.zig+10| ... | ... | @@ -94,3 +94,13 @@ test "inline function call" { |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 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 | 1723 | \\} |
| 1724 | 1724 | \\ |
| 1725 | 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 | 1728 | cases.add("assign too big number to u16", |
| 1729 | 1729 | \\export fn foo() void { |