From a947f97331595df4ee340bbcfcef7241555c687b Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 21 Nov 2023 13:23:24 +0200 Subject: Sema: fix bad error location on field init with field access Closes #14753 --- .../compile_errors/invalid_field_in_struct_value_expression.zig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig b/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig index f1cd96d8e7..251559824e 100644 --- a/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig +++ b/test/cases/compile_errors/invalid_field_in_struct_value_expression.zig @@ -21,6 +21,13 @@ pub export fn entry() void { dump(.{ .field_1 = 123, .field_3 = 456 }); } +pub export fn entry1() void { + const x = Object{ + .abc = 1, + }; + _ = x; +} + // error // backend=stage2 // target=native @@ -29,3 +36,5 @@ pub export fn entry() void { // :1:11: note: struct declared here // :21:30: error: no field named 'field_3' in struct 'tmp.Object' // :15:16: note: struct declared here +// :26:10: error: no field named 'abc' in struct 'tmp.Object' +// :15:16: note: struct declared here -- cgit v1.2.3 From d63298da65df7fa2712bf9e9d65d36cd91af22fa Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 21 Nov 2023 13:44:03 +0200 Subject: InternPool: handle `funcZirBodyInst` for `func_coerced` Closes #18039 --- src/InternPool.zig | 7 +++++++ test/behavior/call.zig | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'test') diff --git a/src/InternPool.zig b/src/InternPool.zig index 10016a9329..11204287f6 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -8301,6 +8301,13 @@ pub fn funcZirBodyInst(ip: *const InternPool, i: Index) Zir.Inst.Index { assert(ip.items.items(.tag)[func_decl_index] == .func_decl); break :b ip.items.items(.data)[func_decl_index] + zir_body_inst_field_index; }, + .func_coerced => { + const datas = ip.items.items(.data); + const uncoerced_func_index: Index = @enumFromInt(ip.extra.items[ + datas[@intFromEnum(i)] + std.meta.fieldIndex(Tag.FuncCoerced, "func").? + ]); + return ip.funcZirBodyInst(uncoerced_func_index); + }, else => unreachable, }; return @enumFromInt(ip.extra.items[extra_index]); diff --git a/test/behavior/call.zig b/test/behavior/call.zig index a476ba1788..b579f85213 100644 --- a/test/behavior/call.zig +++ b/test/behavior/call.zig @@ -499,3 +499,24 @@ test "call inline fn through pointer" { const f = &S.foo; try f(123); } + +test "call coerced function" { + const T = struct { + x: f64, + const T = @This(); + usingnamespace Implement(1); + const F = fn (comptime f64) type; + const Implement: F = opaque { + fn implementer(comptime val: anytype) type { + return opaque { + fn incr(self: T) T { + return .{ .x = self.x + val }; + } + }; + } + }.implementer; + }; + + const a = T{ .x = 3 }; + try std.testing.expect(a.incr().x == 4); +} -- cgit v1.2.3