Skip to content

Commit

Permalink
Fix NR2.0 compiler ICE caused by Generics in Enums
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:
	* resolve/rust-late-name-resolver-2.0.cc:
	Change the late name resolver to enter proper lexical scope during typechecking
	* resolve/rust-late-name-resolver-2.0.h:
	Add needed prototype to header
	* resolve/rust-toplevel-name-resolver-2.0.cc:
	Add generic parameters to enum's scoped RIB to allow for proper name resolution on types.

Signed-off-by: Liam Naddell <[email protected]>
  • Loading branch information
liamnaddell committed Dec 17, 2024
1 parent daa2977 commit 08e4443
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ Late::visit (AST::StructStruct &s)
ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
}

void
Late::visit (AST::Enum &s)
{
auto s_vis = [this, &s] () { AST::DefaultASTVisitor::visit (s); };
ctx.scoped (Rib::Kind::Item, s.get_node_id (), s_vis);
}

void
Late::visit (AST::StructExprStruct &s)
{
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/resolve/rust-late-name-resolver-2.0.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Late : public DefaultResolver
void visit (AST::StructExprStructBase &) override;
void visit (AST::StructExprStructFields &) override;
void visit (AST::StructStruct &) override;
void visit (AST::Enum &) override;
void visit (AST::GenericArgs &) override;
void visit (AST::GenericArg &);

Expand Down
9 changes: 9 additions & 0 deletions gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ TopLevel::visit (AST::EnumItemDiscriminant &variant)
void
TopLevel::visit (AST::Enum &enum_item)
{
auto generic_vis = [this, &enum_item] () {
for (auto &g : enum_item.get_generic_params ())
{
g->accept_vis (*this);
}
};

ctx.scoped (Rib::Kind::Item, enum_item.get_node_id (), generic_vis);

insert_or_error_out (enum_item.get_identifier (), enum_item,
Namespace::Types);

Expand Down

0 comments on commit 08e4443

Please sign in to comment.