Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions unified/ql/lib/codeql/unified/internal/AnalysisQuality.qll
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ module StaticNameResolutionStats implements EntityStatsSig {
or
result.isModuleScopeNode(_) and
result.(NamespaceNode).ref().isIdentifier(this)
) and
// Do not consider a type extension to be a valid target
// TODO: Fix in the AST mapping: type extensions should reference their type, not declare it
not exists(ClassLikeDeclaration cls |
cls.hasModifier("extension") and
result.isIdentifier(cls.getName())
)
}

Expand Down
3 changes: 3 additions & 0 deletions unified/ql/lib/codeql/unified/internal/LocalNameBinding.qll
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ private module LocalNameBindingInput implements LocalNameBindingInputSig<Locatio
exists(ClassLikeDeclaration cls |
getChild(scope, _) = cls and
pattern = cls.getName() and
not cls.hasModifier("extension") and // TODO: Fix in the AST mapping: type extensions should reference their type, not declare it
declaration = cls
)
or
Expand Down Expand Up @@ -382,6 +383,8 @@ class PotentialLocalNameAccess extends Identifier {
this = any(NamedTypeExpr e | not exists(e.getQualifier())).getName()
or
this instanceof NameDeclaration
or
this = any(ClassLikeDeclaration cls | cls.hasModifier("extension")).getName() // TODO: Fix in the AST mapping: type extensions should reference their type, not declare it
Comment thread
hvitved marked this conversation as resolved.
}

LocalName getLocalName() { result = this.(LocalNameBindingOutput::LocalAccess).getLocal() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ private module FolderHeuristic {
exists(TopLevel top, Stmt stmt, NameDeclaration nameDecl |
top.getFile() = file and
stmt = top.getBody().getAStmt() and
not stmt.(ClassLikeDeclaration).hasModifier("extension") and // TODO: target of type extensions should not be seen as a NameDeclaration
not isPrivateToLocalScope(nameDecl) and
nameDecl.getDeclaration() = stmt and
name = nameDecl.getName() and
Expand Down
10 changes: 9 additions & 1 deletion unified/ql/test/library-tests/static-name-binding/test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class F {
typealias G = A // $ access=A

// Members can be accessed through aliases, but references to the alias itself do not bypass the alias.
class H {
class H { // name=H1
let x1: G = nil; // $ access=G
let x2: G.B = nil; // $ access=G access=A.B
let x3: G.B.C = nil; // $ access=G access=A.B access=A.B.C
Expand All @@ -62,3 +62,11 @@ func useI() {
I.two // $ access=I access=I.two
I.three // $ access=I access=I.three
}

protocol P { }

extension H // $ access=H1
: P { } // $ access=P

extension A.B.C // $ MISSING: access=A access=A.B access=A.B.C (`A.B.C` is currently parsed as a single identifier)
: P { } // $ access=P
Loading