Skip to content

Commit 685e67e

Browse files
committed
Unified: Fix bug in UnqualifiedMemberAccess.getAccessingClass()
1 parent 539116f commit 685e67e

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎unified/ql/lib/codeql/unified/internal/StaticNameBinding.qll‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ class NamespaceNode extends NameBindingNode {
445445
exists(this.getOwnMember(name, any(ShadowingKeyOpt opt | opt.asSome() = shadowingKey)))
446446
}
447447

448+
bindingset[n]
449+
private predicate isInheritable(NameBindingNode n) {
450+
isInheritableMemberNode(n) and
451+
// prevent self-inheritance
452+
not exists(ClassLikeDeclaration self |
453+
this.isStaticMemberNamespace(self) and
454+
n.isMember(self)
455+
)
456+
}
457+
448458
/**
449459
* Gets a potential member of this namespace of the given name.
450460
*
@@ -457,7 +467,7 @@ class NamespaceNode extends NameBindingNode {
457467
or
458468
not this.hasOwnMemberWithShadowingKey(name, shadowingKey.asSome()) and
459469
result = this.getAnInheritanceParent().getMemberFull(name, shadowingKey) and
460-
isInheritableMemberNode(result)
470+
this.isInheritable(result)
461471
or
462472
result = this.getAnExtension().getMemberFull(name, shadowingKey)
463473
}
@@ -475,7 +485,7 @@ class NamespaceNode extends NameBindingNode {
475485
parent = this.getAnInheritanceParent() and
476486
not this.hasOwnMemberWithShadowingKey(name, shadowingKey.asSome()) and
477487
result = parent.getMember(name, shadowingKey) and
478-
isInheritableMemberNode(result)
488+
this.isInheritable(result)
479489
)
480490
)
481491
}
@@ -750,8 +760,7 @@ predicate unqualifiedMemberAccess(
750760
ClassLikeDeclaration accessingClass
751761
) {
752762
CachedStage::ref() and
753-
unqualifiedMemberAccessCand(pragma[only_bind_into](access), instanceAccess, target,
754-
pragma[only_bind_into](accessingClass)) and
763+
unqualifiedMemberAccessCand(access, instanceAccess, target, accessingClass) and
755764
accessingClass.getDepth() = unqualifiedMemberAccessDepth(access)
756765
}
757766

‎unified/ql/test/library-tests/static-name-binding/test.expected‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ unqualifiedMemberAccess
3232
| unqualified-access.swift:13:17:13:17 | C | unqualified-access.swift:11:5:14:5 | class ASub.BSub |
3333
| unqualified-access.swift:16:18:16:18 | B | unqualified-access.swift:7:1:20:1 | class ASub |
3434
| unqualified-access.swift:18:17:18:17 | C | unqualified-access.swift:16:5:19:5 | class ASub.BSub2 |
35-
| unqualified-access.swift:24:16:24:19 | Leaf | unqualified-access.swift:23:5:25:5 | class Node.Leaf |
36-
| unqualified-access.swift:24:23:24:26 | Leaf | unqualified-access.swift:23:5:25:5 | class Node.Leaf |
35+
| unqualified-access.swift:24:16:24:19 | Leaf | unqualified-access.swift:22:1:26:1 | class Node |
36+
| unqualified-access.swift:24:23:24:26 | Leaf | unqualified-access.swift:22:1:26:1 | class Node |

0 commit comments

Comments
 (0)