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.
This commit is contained in:
Paolo Tranquilli
2022-07-20 09:13:34 +02:00
parent e1bd4a78ff
commit 3527897eff
4 changed files with 11 additions and 4 deletions

View File

@@ -184,7 +184,7 @@ Stmt:
TypeRepr:
_extends: AstNode
type: Type
type: Type? # type can be absent on unresolved entities
FunctionType:
_extends: AnyFunctionType

View File

@@ -11,7 +11,7 @@ void TypeVisitor::visit(swift::TypeBase* type) {
codeql::TypeRepr TypeVisitor::translateTypeRepr(const swift::TypeRepr& typeRepr, swift::Type type) {
auto entry = dispatcher_.createEntry(typeRepr);
entry.type = dispatcher_.fetchLabel(type);
entry.type = dispatcher_.fetchOptionalLabel(type);
return entry;
}

View File

@@ -7,8 +7,10 @@ class TypeReprBase extends @type_repr, AstNode {
Type getType() {
exists(Type x |
type_reprs(this, x) and
type_repr_types(this, x) and
result = x.resolve()
)
}
predicate hasType() { exists(getType()) }
}

View File

@@ -473,7 +473,12 @@ expr_types( //dir=expr
;
type_reprs( //dir=type
unique int id: @type_repr,
unique int id: @type_repr
);
#keyset[id]
type_repr_types( //dir=type
int id: @type_repr ref,
int type_: @type ref
);