Skip to content

Commit 5f03099

Browse files
committed
Swift: clarify DotSyntaxBaseIgnoredExpr
- Add docstring with implementation note. - Avoid `concat` aggregate in toString(). Still, this class should really be cleaned up in the following ways: - Rename to a sane name at the schema level - Have subtypes that change the return type of getSubExpr to reflect the structure of the desugared closure. E.g. one for methods, one for fields.
1 parent 16a1192 commit 5f03099

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

swift/ql/lib/codeql/swift/elements/expr/DotSyntaxBaseIgnoredExpr.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@ private import codeql.swift.elements.expr.CallExpr
44
private import codeql.swift.elements.expr.TypeExpr
55
private import codeql.swift.elements.decl.MethodDecl
66

7+
/**
8+
* An expression representing a partially applied lookup of an instance property via the receiver's type object.
9+
*
10+
* An example is the sub-expression `SomeClass.instanceMethod` of
11+
* `SomeClass.instanceMethod(someInstance)(arg, ...)`.
12+
*
13+
* Internally, the Swift compiler desugars this AST node type into a closure expression of the form
14+
* `{ (someInstance: SomeClass) in { (arg, ...) in someInstance.instanceMethod(arg, ...) } }`,
15+
* which in turn can be accessed using the `getSubExpr/0` predicate.
16+
*/
717
class DotSyntaxBaseIgnoredExpr extends Generated::DotSyntaxBaseIgnoredExpr {
818
override string toString() {
919
result =
10-
concat(this.getQualifier().(TypeExpr).getTypeRepr().toString()) + "." + this.getMethod()
20+
any(string base |
21+
if exists(this.getQualifier().(TypeExpr).getTypeRepr().toString())
22+
then base = this.getQualifier().(TypeExpr).getTypeRepr().toString() + "."
23+
else base = "."
24+
) + this.getMethod()
1125
}
1226

1327
/**

0 commit comments

Comments
 (0)