AstGen: do not set decl_line for containers

Previously AstGen would set decl_line for containers so that
declarations inside them would be relative to the start of the
container but Sema was not aware of the line offset of the container
and would make them relative to the containers parent decl which
would then break for generic structs.

In the future when working on incremental compilation it will likely
be better to communicate the line delta to Sema but for now this
is a simpler fix that correctly handles the non-incremental case.

Closes #12725
Closes #12818
This commit is contained in:
Veikka Tuominen 2022-09-29 18:51:04 +03:00
parent b3c6d774d2
commit 3122601242

View File

@ -4233,13 +4233,10 @@ fn structDeclInner(
// are in scope, so that field types, alignments, and default value expressions
// can refer to decls within the struct itself.
astgen.advanceSourceCursorToNode(node);
// If `node == 0` then this is the root struct and all the declarations should
// be relative to the beginning of the file.
const decl_line = if (node == 0) 0 else astgen.source_line;
var block_scope: GenZir = .{
.parent = &namespace.base,
.decl_node_index = node,
.decl_line = decl_line,
.decl_line = gz.decl_line,
.astgen = astgen,
.force_comptime = true,
.instructions = gz.instructions,
@ -4439,7 +4436,7 @@ fn unionDeclInner(
var block_scope: GenZir = .{
.parent = &namespace.base,
.decl_node_index = node,
.decl_line = astgen.source_line,
.decl_line = gz.decl_line,
.astgen = astgen,
.force_comptime = true,
.instructions = gz.instructions,
@ -4722,7 +4719,7 @@ fn containerDecl(
var block_scope: GenZir = .{
.parent = &namespace.base,
.decl_node_index = node,
.decl_line = astgen.source_line,
.decl_line = gz.decl_line,
.astgen = astgen,
.force_comptime = true,
.instructions = gz.instructions,
@ -4827,7 +4824,7 @@ fn containerDecl(
var block_scope: GenZir = .{
.parent = &namespace.base,
.decl_node_index = node,
.decl_line = astgen.source_line,
.decl_line = gz.decl_line,
.astgen = astgen,
.force_comptime = true,
.instructions = gz.instructions,