From 6f5a438946dce2b201acf5b7bbe42977bc990cc4 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 29 Nov 2022 18:40:28 +0200 Subject: [PATCH] AstGen: unstack block scope when creating opaque type Closes #13697 --- src/AstGen.zig | 1 + test/behavior/basic.zig | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/AstGen.zig b/src/AstGen.zig index e6f83dc00b..6836b4f1cc 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -5070,6 +5070,7 @@ fn containerDecl( try astgen.extra.ensureUnusedCapacity(gpa, decls_slice.len); astgen.extra.appendSliceAssumeCapacity(decls_slice); + block_scope.unstack(); try gz.addNamespaceCaptures(&namespace); return rvalue(gz, ri, indexToRef(decl_inst), node); }, diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 7351891959..3fc1cda04d 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -1127,3 +1127,14 @@ test "pointer to zero sized global is mutable" { }; try expect(@TypeOf(&S.thing) == *S.Thing); } + +test "returning an opaque type from a function" { + const S = struct { + fn foo(comptime a: u32) type { + return opaque { + const b = a; + }; + } + }; + try expect(S.foo(123).b == 123); +}