diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-08-20 17:44:03 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-08-20 17:44:03 -0700 |
| commit | f0176eec4a744c17fc49cbd63c67179887005935 (patch) | |
| tree | b7efae8b8cfe53a9496cbd4252886a644e4c3bba /src | |
| parent | 6c55d854cffbe7a518e8ec62f746585ddc68ebbf (diff) | |
| download | zig-f0176eec4a744c17fc49cbd63c67179887005935.tar.gz zig-f0176eec4a744c17fc49cbd63c67179887005935.zip | |
stage2: support comptime fn call returning type
...when the field type expressions reference locals as well as
comptime function parameters.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 78f0948623..8ffc828fba 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2623,7 +2623,18 @@ fn analyzeCall( defer sema.fn_ret_ty = parent_fn_ret_ty; _ = try sema.analyzeBody(&child_block, fn_info.body); - break :res try sema.analyzeBlockBody(block, call_src, &child_block, merges); + const result = try sema.analyzeBlockBody(block, call_src, &child_block, merges); + + // Much like in `Module.semaDecl`, if the result is a struct or union type, + // we need to resolve the field type expressions right here, right now, while + // the child `Sema` is still available, with the AIR instruction map intact, + // because the field type expressions may reference into it. + if (sema.typeOf(result).zigTypeTag() == .Type) { + const ty = try sema.analyzeAsType(&child_block, call_src, result); + try sema.resolveDeclFields(&child_block, call_src, ty); + } + + break :res result; } else if (func_ty_info.is_generic) res: { const func_val = try sema.resolveConstValue(block, func_src, func); const module_fn = func_val.castTag(.function).?.data; |
