| author | |
| committer | |
| log | 373b3586a1b1d6a3989220a8aac0d1c30f9fdb3a |
| tree | 751447d115b473b7794bd14583cc2d9c0ea353ae |
| parent | 0d8646d262ebc3db6631421db8fc79228b6622f8 |
closes #9133 files changed, 29 insertions(+), 1 deletions(-)
src/ir.cpp+13-1| ... | ... | @@ -11395,7 +11395,19 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc |
| 11395 | 11395 | } |
| 11396 | 11396 | break; |
| 11397 | 11397 | case VarClassRequiredAny: |
| 11398 | // OK | |
| 11398 | if (casted_init_value->value.special == ConstValSpecialStatic && | |
| 11399 | casted_init_value->value.type->id == TypeTableEntryIdFn && | |
| 11400 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) | |
| 11401 | { | |
| 11402 | var_class_requires_const = true; | |
| 11403 | if (!var->src_is_const && !is_comptime_var) { | |
| 11404 | ErrorMsg *msg = ir_add_error_node(ira, source_node, | |
| 11405 | buf_sprintf("functions marked inline must be stored in const or comptime var")); | |
| 11406 | AstNode *proto_node = casted_init_value->value.data.x_ptr.data.fn.fn_entry->proto_node; | |
| 11407 | add_error_note(ira->codegen, msg, proto_node, buf_sprintf("declared here")); | |
| 11408 | result_type = ira->codegen->builtin_types.entry_invalid; | |
| 11409 | } | |
| 11410 | } | |
| 11399 | 11411 | break; |
| 11400 | 11412 | } |
| 11401 | 11413 | } |
test/cases/fn.zig+7| ... | ... | @@ -104,3 +104,10 @@ test "number literal as an argument" { |
| 104 | 104 | fn numberLiteralArg(a: var) void { |
| 105 | 105 | assert(a == 3); |
| 106 | 106 | } |
| 107 | ||
| 108 | test "assign inline fn to const variable" { | |
| 109 | const a = inlineFn; | |
| 110 | a(); | |
| 111 | } | |
| 112 | ||
| 113 | inline fn inlineFn() void { } |
test/compile_errors.zig+9| ... | ... | @@ -1,6 +1,15 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn addCases(cases: &tests.CompileErrorContext) void { |
| 4 | cases.add("assign inline fn to non-comptime var", | |
| 5 | \\export fn entry() void { | |
| 6 | \\ var a = b; | |
| 7 | \\} | |
| 8 | \\inline fn b() void { } | |
| 9 | , | |
| 10 | ".tmp_source.zig:2:5: error: functions marked inline must be stored in const or comptime var", | |
| 11 | ".tmp_source.zig:4:8: note: declared here"); | |
| 12 | ||
| 4 | 13 | cases.add("wrong type passed to @panic", |
| 5 | 14 | \\export fn entry() void { |
| 6 | 15 | \\ var e = error.Foo; |