Skip to content

Commit 7c3cadc

Browse files
committed
Swift: extract OpenedArchetypeType
1 parent 3bacb18 commit 7c3cadc

10 files changed

+63
-5
lines changed

swift/extractor/visitors/TypeVisitor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,10 @@ codeql::BuiltinVectorType TypeVisitor::translateBuiltinVectorType(
367367
const swift::BuiltinVectorType& type) {
368368
return createTypeEntry(type);
369369
}
370-
370+
codeql::OpenedArchetypeType TypeVisitor::translateOpenedArchetypeType(
371+
const swift::OpenedArchetypeType& type) {
372+
auto entry = createTypeEntry(type);
373+
fillArchetypeType(type, entry);
374+
return entry;
375+
}
371376
} // namespace codeql

swift/extractor/visitors/TypeVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class TypeVisitor : public TypeVisitorBase<TypeVisitor> {
6868
codeql::BuiltinUnsafeValueBufferType translateBuiltinUnsafeValueBufferType(
6969
const swift::BuiltinUnsafeValueBufferType& type);
7070
codeql::BuiltinVectorType translateBuiltinVectorType(const swift::BuiltinVectorType& type);
71+
codeql::OpenedArchetypeType translateOpenedArchetypeType(const swift::OpenedArchetypeType& type);
7172

7273
private:
7374
void fillType(const swift::TypeBase& type, codeql::Type& entry);

swift/ql/test/extractor-tests/generated/type/OpenedArchetypeType/MISSING_SOURCE.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| C & P1 & P2 | getName: | C & P1 & P2 | getCanonicalType: | C & P1 & P2 | getInterfaceType: | \u03c4_0_0 |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from OpenedArchetypeType x, string getName, Type getCanonicalType, Type getInterfaceType
6+
where
7+
toBeTested(x) and
8+
not x.isUnknown() and
9+
getName = x.getName() and
10+
getCanonicalType = x.getCanonicalType() and
11+
getInterfaceType = x.getInterfaceType()
12+
select x, "getName:", getName, "getCanonicalType:", getCanonicalType, "getInterfaceType:",
13+
getInterfaceType
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| C & P1 & P2 | 0 | opened_archetypes.swift:3:1:3:14 | P1 |
2+
| C & P1 & P2 | 1 | opened_archetypes.swift:9:1:9:14 | P2 |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from OpenedArchetypeType x, int index
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, index, x.getProtocol(index)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| C & P1 & P2 | C |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// generated by codegen/codegen.py
2+
import codeql.swift.elements
3+
import TestUtils
4+
5+
from OpenedArchetypeType x
6+
where toBeTested(x) and not x.isUnknown()
7+
select x, x.getSuperclass()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// code inspired by https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md
2+
3+
protocol P1 {}
4+
5+
func isFoo<T: P1>(_: T) -> Bool {
6+
return true
7+
}
8+
9+
protocol P2 {}
10+
11+
class C {}
12+
13+
// will be ok with swift 5.7
14+
// func test(value: any P1 & P2 & C) -> Bool { return isFoo(value) }
15+
16+
extension P1 {
17+
var isFooMember: Bool {
18+
isFoo(self)
19+
}
20+
}
21+
22+
23+
func testMember(value: any P1 & P2 & C) -> Bool {
24+
return value.isFooMember // here the existential type is implicitly "opened"
25+
}

0 commit comments

Comments
 (0)