Skip to content

Commit 86b8ca6

Browse files
committed
[Compile Time Constant Extraction] Look through underlying-to-opaque conversions
Resolves rdar://106006689
1 parent ee9b476 commit 86b8ca6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Diff for: lib/ConstExtract/ConstExtract.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ static std::shared_ptr<CompileTimeValue> extractCompileTimeValue(Expr *expr) {
306306
return std::make_shared<TypeValue>(dotSelfExpr->getType());
307307
}
308308

309+
case ExprKind::UnderlyingToOpaque: {
310+
auto underlyingToOpaque = cast<UnderlyingToOpaqueExpr>(expr);
311+
return extractCompileTimeValue(underlyingToOpaque->getSubExpr());
312+
}
313+
309314
default: {
310315
break;
311316
}

Diff for: test/ConstExtraction/ExtractUnderlyingToOpaque.swift

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: echo "[MyProto]" > %t/protocols.json
3+
4+
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractLiterals.swiftconstvalues -const-gather-protocols-file %t/protocols.json -primary-file %s
5+
// RUN: cat %t/ExtractLiterals.swiftconstvalues 2>&1 | %FileCheck %s
6+
7+
protocol MyProto {}
8+
protocol Bird {}
9+
struct UnderlyingToOpaquePropertyStruct : MyProto {
10+
var warbler: some Bird {
11+
Warbler("blue")
12+
}
13+
}
14+
15+
public struct Warbler : Bird {
16+
let belly: String = "yellow"
17+
init(_ color: String = "red") {
18+
self.belly = color
19+
}
20+
}
21+
22+
// CHECK: "valueKind": "InitCall",
23+
// CHECK-NEXT: "value": {
24+
// CHECK-NEXT: "type": "ExtractUnderlyingToOpaque.Warbler",
25+
// CHECK-NEXT: "arguments": [
26+
// CHECK-NEXT: {
27+
// CHECK-NEXT: "label": "",
28+
// CHECK-NEXT: "type": "Swift.String",
29+
// CHECK-NEXT: "valueKind": "RawLiteral",
30+
// CHECK-NEXT: "value": "blue"
31+
// CHECK-NEXT: }
32+
// CHECK-NEXT: ]
33+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)