authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-04 14:28:58+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-05-04 14:28:58+03:00
logadc444ceeb91c06a6ee84dc4e4874294a41dee45
treed69253d7044ad741b64ee61abed86d8a2cb7a890
parente72f45475d05fb446e48d3e34e6c8e367916bd50
signature Commit is signed but in an unrecognized format.

fix missing compile error on call assigned to const


2 files changed, 33 insertions(+), 0 deletions(-)

src/ir.cpp+10
......@@ -20000,6 +20000,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
2000020000 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2000120001 return result_loc;
2000220002 }
20003 if (result_loc->value->type->data.pointer.is_const) {
20004 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
20005 return ira->codegen->invalid_inst_gen;
20006 }
20007
2000320008 IrInstGen *dummy_value = ir_const(ira, source_instr, impl_fn_type_id->return_type);
2000420009 dummy_value->value->special = ConstValSpecialRuntime;
2000520010 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,
......@@ -20138,6 +20143,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
2013820143 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
2013920144 return result_loc;
2014020145 }
20146 if (result_loc->value->type->data.pointer.is_const) {
20147 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
20148 return ira->codegen->invalid_inst_gen;
20149 }
20150
2014120151 IrInstGen *dummy_value = ir_const(ira, source_instr, return_type);
2014220152 dummy_value->value->special = ConstValSpecialRuntime;
2014320153 IrInstGen *dummy_result = ir_implicit_cast2(ira, source_instr,
test/compile_errors.zig+23
......@@ -2,6 +2,29 @@ const tests = @import("tests.zig");
22const std = @import("std");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add("call assigned to constant",
6 \\const Foo = struct {
7 \\ x: i32,
8 \\};
9 \\fn foo() Foo {
10 \\ return .{ .x = 42 };
11 \\}
12 \\fn bar(val: var) Foo {
13 \\ return .{ .x = val };
14 \\}
15 \\export fn entry() void {
16 \\ const baz: Foo = undefined;
17 \\ baz = foo();
18 \\}
19 \\export fn entry1() void {
20 \\ const baz: Foo = undefined;
21 \\ baz = bar(42);
22 \\}
23 , &[_][]const u8{
24 "tmp.zig:12:14: error: cannot assign to constant",
25 "tmp.zig:16:14: error: cannot assign to constant",
26 });
27
528 cases.add("invalid pointer syntax",
629 \\export fn foo() void {
730 \\ var guid: *:0 const u8 = undefined;