Skip to content

Commit d870321

Browse files
committed
Swift: Extract type aliases.
1 parent d0fa7c7 commit d870321

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

swift/extractor/translators/DeclTranslator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ std::optional<codeql::AssociatedTypeDecl> DeclTranslator::translateAssociatedTyp
206206
std::optional<codeql::TypeAliasDecl> DeclTranslator::translateTypeAliasDecl(
207207
const swift::TypeAliasDecl& decl) {
208208
if (auto entry = createNamedEntry(decl)) {
209+
entry->aliased_type = dispatcher.fetchLabel(decl.getUnderlyingType());
209210
fillTypeDecl(decl, *entry);
210211
return entry;
211212
}

swift/ql/lib/swift.dbscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ param_decl_property_wrapper_local_wrapped_vars( //dir=decl
670670
);
671671

672672
type_alias_decls( //dir=decl
673-
unique int id: @type_alias_decl
673+
unique int id: @type_alias_decl,
674+
int aliased_type: @type_or_none ref
674675
);
675676

676677
class_decls( //dir=decl

swift/schema.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,18 @@ class OpaqueTypeDecl(GenericTypeDecl):
324324
opaque_generic_params: list["GenericTypeParamType"]
325325

326326
class TypeAliasDecl(GenericTypeDecl):
327-
pass
327+
"""
328+
A declaration of a type alias to another type. For example:
329+
```
330+
typealias MyInt = Int
331+
```
332+
"""
333+
aliased_type: Type | doc("aliased type on the right-hand side of this type alias declaration") | desc("""
334+
For example the aliased type of `MyInt` in the following code is `Int`:
335+
```
336+
typealias MyInt = Int
337+
```
338+
""")
328339

329340
class ClassDecl(NominalTypeDecl):
330341
pass

0 commit comments

Comments
 (0)