Skip to content

Commit 3527897

Browse files
committed
Swift: make type optional in TypeRepr
A type representation may not have a type in unresolved things, which for example pop up in inactive `#if` clauses.
1 parent e1bd4a7 commit 3527897

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Stmt:
184184

185185
TypeRepr:
186186
_extends: AstNode
187-
type: Type
187+
type: Type? # type can be absent on unresolved entities
188188

189189
FunctionType:
190190
_extends: AnyFunctionType

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void TypeVisitor::visit(swift::TypeBase* type) {
1111

1212
codeql::TypeRepr TypeVisitor::translateTypeRepr(const swift::TypeRepr& typeRepr, swift::Type type) {
1313
auto entry = dispatcher_.createEntry(typeRepr);
14-
entry.type = dispatcher_.fetchLabel(type);
14+
entry.type = dispatcher_.fetchOptionalLabel(type);
1515
return entry;
1616
}
1717

swift/ql/lib/codeql/swift/generated/type/TypeRepr.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ class TypeReprBase extends @type_repr, AstNode {
77

88
Type getType() {
99
exists(Type x |
10-
type_reprs(this, x) and
10+
type_repr_types(this, x) and
1111
result = x.resolve()
1212
)
1313
}
14+
15+
predicate hasType() { exists(getType()) }
1416
}

swift/ql/lib/swift.dbscheme

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,12 @@ expr_types( //dir=expr
473473
;
474474

475475
type_reprs( //dir=type
476-
unique int id: @type_repr,
476+
unique int id: @type_repr
477+
);
478+
479+
#keyset[id]
480+
type_repr_types( //dir=type
481+
int id: @type_repr ref,
477482
int type_: @type ref
478483
);
479484

0 commit comments

Comments
 (0)