Skip to content

Commit 1fc2bc4

Browse files
committed
Swift: really fix tests
1 parent 3ed783d commit 1fc2bc4

File tree

10 files changed

+99
-85
lines changed

10 files changed

+99
-85
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ LookupExpr:
446446
_extends: Expr
447447
_children:
448448
base_expr: Expr
449-
member: Decl
449+
member: Decl?
450450

451451
MakeTemporarilyEscapableExpr:
452452
_extends: Expr

swift/extractor/visitors/ExprVisitor.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,11 @@ class ExprVisitor : public AstVisitorBase<ExprVisitor> {
643643
void emitLookupExpr(const swift::LookupExpr* expr, TrapLabel<LookupExprTag> label) {
644644
assert(expr->getBase() && "LookupExpr has getBase()");
645645
auto baseLabel = dispatcher_.fetchLabel(expr->getBase());
646-
assert(expr->hasDecl() && "LookupExpr has decl");
647-
auto declLabel = dispatcher_.fetchLabel(expr->getDecl().getDecl());
648-
dispatcher_.emit(LookupExprsTrap{label, baseLabel, declLabel});
646+
dispatcher_.emit(LookupExprsTrap{label, baseLabel});
647+
if (expr->hasDecl()) {
648+
auto declLabel = dispatcher_.fetchLabel(expr->getDecl().getDecl());
649+
dispatcher_.emit(LookupExprMembersTrap{label, declLabel});
650+
}
649651
}
650652

651653
/*
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
private import codeql.swift.generated.expr.TypeExpr
22

33
class TypeExpr extends TypeExprBase {
4-
override string toString() { result = this.getTypeRepr().toString() }
4+
override string toString() { result = this.getType().toString() }
55
}

swift/ql/lib/codeql/swift/generated/GetImmediateParent.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Element getAnImmediateChild(Element e) {
102102
or
103103
lazy_initializer_exprs(e, x)
104104
or
105-
lookup_exprs(e, x, _)
105+
lookup_exprs(e, x)
106106
or
107107
make_temporarily_escapable_exprs(e, x, _, _)
108108
or

swift/ql/lib/codeql/swift/generated/expr/LookupExpr.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import codeql.swift.elements.expr.Expr
55
class LookupExprBase extends @lookup_expr, Expr {
66
Expr getBaseExpr() {
77
exists(Expr x |
8-
lookup_exprs(this, x, _) and
8+
lookup_exprs(this, x) and
99
result = x.resolve()
1010
)
1111
}
1212

1313
Decl getMember() {
1414
exists(Decl x |
15-
lookup_exprs(this, _, x) and
15+
lookup_expr_members(this, x) and
1616
result = x.resolve()
1717
)
1818
}
19+
20+
predicate hasMember() { exists(getMember()) }
1921
}

swift/ql/lib/swift.dbscheme

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,12 @@ lazy_initializer_exprs(
955955
#keyset[id]
956956
lookup_exprs(
957957
int id: @lookup_expr ref,
958-
int base_expr: @expr ref,
958+
int base_expr: @expr ref
959+
);
960+
961+
#keyset[id]
962+
lookup_expr_members(
963+
int id: @lookup_expr ref,
959964
int member: @decl ref
960965
);
961966

swift/ql/test/extractor-tests/expressions/all.expected

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
| expressions.swift:15:9:15:9 | x | DeclRefExpr |
2828
| expressions.swift:15:9:15:14 | ... call to !=(_:_:) ... | BinaryExpr |
2929
| expressions.swift:15:11:15:11 | !=(_:_:) | DeclRefExpr |
30-
| expressions.swift:15:11:15:11 | FixedTypeRepr | TypeExpr |
30+
| expressions.swift:15:11:15:11 | Int.Type | TypeExpr |
3131
| expressions.swift:15:11:15:11 | call to !=(_:_:) | DotSyntaxCallExpr |
3232
| expressions.swift:15:14:15:14 | 0 | IntegerLiteralExpr |
33-
| expressions.swift:16:11:16:11 | SimpleIdentTypeRepr | TypeExpr |
33+
| expressions.swift:16:11:16:11 | AnError.Type | TypeExpr |
3434
| expressions.swift:16:11:16:19 | (Error) ... | ErasureExpr |
3535
| expressions.swift:16:11:16:19 | call to ... | DotSyntaxCallExpr |
3636
| expressions.swift:16:19:16:19 | failed | DeclRefExpr |
@@ -43,7 +43,7 @@
4343
| expressions.swift:21:6:21:16 | (()?) ... | InjectIntoOptionalExpr |
4444
| expressions.swift:21:6:21:16 | call to failure(_:) | CallExpr |
4545
| expressions.swift:21:14:21:14 | 11 | IntegerLiteralExpr |
46-
| expressions.swift:27:13:27:13 | SimpleIdentTypeRepr | TypeExpr |
46+
| expressions.swift:27:13:27:13 | Klass.Type | TypeExpr |
4747
| expressions.swift:27:13:27:13 | call to ... | ConstructorRefCallExpr |
4848
| expressions.swift:27:13:27:13 | init | DeclRefExpr |
4949
| expressions.swift:27:13:27:19 | call to ... | CallExpr |
@@ -90,7 +90,7 @@
9090
| expressions.swift:42:12:42:12 | x | DeclRefExpr |
9191
| expressions.swift:42:12:42:16 | ... call to +(_:_:) ... | BinaryExpr |
9292
| expressions.swift:42:14:42:14 | +(_:_:) | DeclRefExpr |
93-
| expressions.swift:42:14:42:14 | FixedTypeRepr | TypeExpr |
93+
| expressions.swift:42:14:42:14 | Int.Type | TypeExpr |
9494
| expressions.swift:42:14:42:14 | call to +(_:_:) | DotSyntaxCallExpr |
9595
| expressions.swift:42:16:42:16 | y | DeclRefExpr |
9696
| expressions.swift:44:1:44:1 | closured(closure:) | DeclRefExpr |
@@ -99,7 +99,7 @@
9999
| expressions.swift:45:12:45:12 | x | DeclRefExpr |
100100
| expressions.swift:45:12:45:16 | ... call to +(_:_:) ... | BinaryExpr |
101101
| expressions.swift:45:14:45:14 | +(_:_:) | DeclRefExpr |
102-
| expressions.swift:45:14:45:14 | FixedTypeRepr | TypeExpr |
102+
| expressions.swift:45:14:45:14 | Int.Type | TypeExpr |
103103
| expressions.swift:45:14:45:14 | call to +(_:_:) | DotSyntaxCallExpr |
104104
| expressions.swift:45:16:45:16 | y | DeclRefExpr |
105105
| expressions.swift:47:1:47:1 | closured(closure:) | DeclRefExpr |
@@ -108,7 +108,7 @@
108108
| expressions.swift:47:19:47:19 | $0 | DeclRefExpr |
109109
| expressions.swift:47:19:47:24 | ... call to +(_:_:) ... | BinaryExpr |
110110
| expressions.swift:47:22:47:22 | +(_:_:) | DeclRefExpr |
111-
| expressions.swift:47:22:47:22 | FixedTypeRepr | TypeExpr |
111+
| expressions.swift:47:22:47:22 | Int.Type | TypeExpr |
112112
| expressions.swift:47:22:47:22 | call to +(_:_:) | DotSyntaxCallExpr |
113113
| expressions.swift:47:24:47:24 | $1 | DeclRefExpr |
114114
| expressions.swift:48:1:48:1 | closured(closure:) | DeclRefExpr |
@@ -117,13 +117,13 @@
117117
| expressions.swift:48:12:48:12 | $0 | DeclRefExpr |
118118
| expressions.swift:48:12:48:17 | ... call to +(_:_:) ... | BinaryExpr |
119119
| expressions.swift:48:15:48:15 | +(_:_:) | DeclRefExpr |
120-
| expressions.swift:48:15:48:15 | FixedTypeRepr | TypeExpr |
120+
| expressions.swift:48:15:48:15 | Int.Type | TypeExpr |
121121
| expressions.swift:48:15:48:15 | call to +(_:_:) | DotSyntaxCallExpr |
122122
| expressions.swift:48:17:48:17 | $1 | DeclRefExpr |
123123
| expressions.swift:54:1:54:1 | _ | DiscardAssignmentExpr |
124124
| expressions.swift:54:1:54:8 | ... = ... | AssignExpr |
125125
| expressions.swift:54:5:54:8 | #keyPath(...) | KeyPathExpr |
126-
| expressions.swift:54:6:54:6 | SimpleIdentTypeRepr | TypeExpr |
126+
| expressions.swift:54:6:54:6 | (no string representation) | TypeExpr |
127127
| expressions.swift:54:6:54:8 | ... .x | UnresolvedDotExpr |
128128
| expressions.swift:58:16:58:16 | 1234 | IntegerLiteralExpr |
129129
| expressions.swift:59:1:59:1 | unsafeFunction(pointer:) | DeclRefExpr |
@@ -143,7 +143,7 @@
143143
| expressions.swift:64:8:64:8 | x | DeclRefExpr |
144144
| expressions.swift:64:8:64:12 | ... call to <(_:_:) ... | BinaryExpr |
145145
| expressions.swift:64:10:64:10 | <(_:_:) | DeclRefExpr |
146-
| expressions.swift:64:10:64:10 | FixedTypeRepr | TypeExpr |
146+
| expressions.swift:64:10:64:10 | Int.Type | TypeExpr |
147147
| expressions.swift:64:10:64:10 | call to <(_:_:) | DotSyntaxCallExpr |
148148
| expressions.swift:64:12:64:12 | 0 | IntegerLiteralExpr |
149149
| expressions.swift:73:5:73:5 | .xx | MemberRefExpr |
@@ -163,7 +163,7 @@
163163
| expressions.swift:79:5:79:21 | self = ... | RebindSelfInConstructorExpr |
164164
| expressions.swift:79:11:79:11 | init | OtherConstructorDeclRefExpr |
165165
| expressions.swift:79:19:79:19 | 22 | IntegerLiteralExpr |
166-
| expressions.swift:83:15:83:15 | SimpleIdentTypeRepr | TypeExpr |
166+
| expressions.swift:83:15:83:15 | Derived.Type | TypeExpr |
167167
| expressions.swift:83:15:83:15 | call to ... | ConstructorRefCallExpr |
168168
| expressions.swift:83:15:83:15 | init | DeclRefExpr |
169169
| expressions.swift:83:15:83:23 | call to ... | CallExpr |
@@ -178,18 +178,18 @@
178178
| expressions.swift:88:1:88:6 | ...[...] | SubscriptExpr |
179179
| expressions.swift:88:1:88:7 | ...! | ForceValueExpr |
180180
| expressions.swift:88:3:88:3 | a | StringLiteralExpr |
181-
| expressions.swift:92:14:92:14 | SimpleIdentTypeRepr | TypeExpr |
181+
| expressions.swift:92:14:92:14 | Unmanaged<ToPtr>.Type | TypeExpr |
182182
| expressions.swift:92:14:92:24 | call to passRetained(_:) | DotSyntaxCallExpr |
183183
| expressions.swift:92:14:92:44 | call to ... | CallExpr |
184184
| expressions.swift:92:14:92:46 | call to toOpaque() | DotSyntaxCallExpr |
185185
| expressions.swift:92:14:92:55 | call to ... | CallExpr |
186186
| expressions.swift:92:24:92:24 | passRetained(_:) | DeclRefExpr |
187-
| expressions.swift:92:37:92:37 | SimpleIdentTypeRepr | TypeExpr |
187+
| expressions.swift:92:37:92:37 | ToPtr.Type | TypeExpr |
188188
| expressions.swift:92:37:92:37 | call to ... | ConstructorRefCallExpr |
189189
| expressions.swift:92:37:92:37 | init | DeclRefExpr |
190190
| expressions.swift:92:37:92:43 | call to ... | CallExpr |
191191
| expressions.swift:92:46:92:46 | toOpaque() | DeclRefExpr |
192-
| expressions.swift:93:1:93:16 | ...<...> | TypeExpr |
192+
| expressions.swift:93:1:93:16 | Unmanaged<ToPtr>.Type | TypeExpr |
193193
| expressions.swift:93:1:93:18 | call to fromOpaque(_:) | DotSyntaxCallExpr |
194194
| expressions.swift:93:1:93:35 | call to ... | CallExpr |
195195
| expressions.swift:93:18:93:18 | fromOpaque(_:) | DeclRefExpr |
@@ -242,5 +242,5 @@
242242
| expressions.swift:154:22:154:56 | \\...[...] | KeyPathApplicationExpr |
243243
| expressions.swift:154:33:154:33 | keyPathB | DeclRefExpr |
244244
| expressions.swift:154:52:154:55 | #keyPath(...) | KeyPathExpr |
245-
| expressions.swift:154:53:154:53 | SimpleIdentTypeRepr | TypeExpr |
245+
| expressions.swift:154:53:154:53 | (no string representation) | TypeExpr |
246246
| expressions.swift:154:53:154:55 | ... .x | UnresolvedDotExpr |
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
| unresolved_dot_expr.swift:5:6:5:8 | UnresolvedDotExpr | getBase: | unresolved_dot_expr.swift:5:6:5:6 | SimpleIdentTypeRepr | getName: | x |
2-
| unresolved_dot_expr.swift:11:6:11:8 | UnresolvedDotExpr | getBase: | unresolved_dot_expr.swift:11:6:11:6 | SimpleIdentTypeRepr | getName: | a |
3-
| unresolved_dot_expr.swift:11:6:11:10 | UnresolvedDotExpr | getBase: | unresolved_dot_expr.swift:11:6:11:8 | UnresolvedDotExpr | getName: | x |
1+
| main.swift:5:6:5:8 | ... .x | getBase: | main.swift:5:6:5:6 | (no string representation) | getName: | x |
2+
| main.swift:11:6:11:8 | ... .a | getBase: | main.swift:11:6:11:6 | (no string representation) | getName: | a |
3+
| main.swift:11:6:11:10 | ... .x | getBase: | main.swift:11:6:11:8 | ... .a | getName: | x |
4+
| unresolved_dot_expr.swift:5:6:5:8 | ... .x | getBase: | unresolved_dot_expr.swift:5:6:5:6 | (no string representation) | getName: | x |
5+
| unresolved_dot_expr.swift:11:6:11:8 | ... .a | getBase: | unresolved_dot_expr.swift:11:6:11:6 | (no string representation) | getName: | a |
6+
| unresolved_dot_expr.swift:11:6:11:10 | ... .x | getBase: | unresolved_dot_expr.swift:11:6:11:8 | ... .a | getName: | x |

0 commit comments

Comments
 (0)