Fix class/var named identically to an enclosing-scope type (#7827) (#7828)

Fixes #7827.
This commit is contained in:
Tom Jackson
2026-06-23 20:43:31 -04:00
committed by GitHub
parent 0cd13f80c9
commit 2baca68f86
4 changed files with 80 additions and 2 deletions
+8 -2
View File
@@ -3562,12 +3562,18 @@ class LinkDotResolveVisitor final : public VNVisitor {
}
static VSymEnt* findIdFallbackSkipMemberDType(VSymEnt* lookp, const string& name) {
VSymEnt* shadowEntp = nullptr; // Shadowing variable: not a type, kept for error report
while (lookp) {
VSymEnt* const foundp = lookp->findIdFlat(name);
if (foundp && !VN_IS(foundp->nodep(), MemberDType)) return foundp;
if (foundp && !VN_IS(foundp->nodep(), MemberDType)) {
// A variable is not a type candidate (IEEE 1800-2023 6.18); skip it so an
// enclosing type is found, but keep it to preserve the "found: VAR" error.
if (!VN_IS(foundp->nodep(), Var)) return foundp;
if (!shadowEntp) shadowEntp = foundp;
}
lookp = lookp->fallbackp();
}
return nullptr;
return shadowEntp;
}
void symIterateChildren(AstNode* nodep, VSymEnt* symp) {