Skip to content

Commit

Permalink
Prevent static access to non-static class member
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Bieganski <[email protected]>
  • Loading branch information
kbieganski committed Oct 25, 2023
1 parent e36fee8 commit 1736a02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/V3LinkDot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2740,9 +2740,8 @@ class LinkDotResolveVisitor final : public VNVisitor {
}
} else {
if (staticAccess && !varp->lifetime().isStatic() && !varp->isParam()) {
// TODO bug4077
// nodep->v3error("Static access to non-static member variable "
// << varp->prettyNameQ() << endl);
nodep->v3error("Static access to non-static member variable "
<< varp->prettyNameQ() << endl);
}
AstVarRef* const refp = new AstVarRef{
nodep->fileline(), varp, VAccess::READ}; // lvalue'ness computed later
Expand Down Expand Up @@ -3187,10 +3186,9 @@ class LinkDotResolveVisitor final : public VNVisitor {
AstNodeFTask* const taskp
= foundp ? VN_CAST(foundp->nodep(), NodeFTask) : nullptr; // Maybe nullptr
if (taskp) {
if (staticAccess && !taskp->isStatic()) {
// TODO bug4077
// nodep->v3error("Static access to non-static task/function "
// << taskp->prettyNameQ() << endl);
if (staticAccess && taskp->classMethod() && !taskp->isStatic()) {
nodep->v3error("Static access to non-static task/function "
<< taskp->prettyNameQ() << endl);
}
nodep->taskp(taskp);
nodep->classOrPackagep(foundp->classOrPackagep());
Expand Down
4 changes: 2 additions & 2 deletions test_regress/t/t_class_member_bad3.pl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
scenarios(linter => 1);

lint(
# fails => 1, # TODO bug4077
# expect_filename => $Self->{golden_filename},
fails => 1,
expect_filename => $Self->{golden_filename},
);

ok(1);
Expand Down

0 comments on commit 1736a02

Please sign in to comment.