[Compile Time Constant Extraction] Extract InjectIntoOptional arguments

Resolves rdar://106059663
This commit is contained in:
Artem Chikin
2023-03-01 09:22:45 -08:00
parent a64fc3b66d
commit ee9b4766ad
2 changed files with 37 additions and 0 deletions

View File

@@ -138,6 +138,8 @@ extractFunctionArguments(const ArgumentList *args) {
if (decl->hasDefaultExpr()) { if (decl->hasDefaultExpr()) {
argExpr = decl->getTypeCheckedDefaultExpr(); argExpr = decl->getTypeCheckedDefaultExpr();
} }
} else if (auto optionalInject = dyn_cast<InjectIntoOptionalExpr>(argExpr)) {
argExpr = optionalInject->getSubExpr();
} }
parameters.push_back({label, type, extractCompileTimeValue(argExpr)}); parameters.push_back({label, type, extractCompileTimeValue(argExpr)});
} }

View File

@@ -0,0 +1,35 @@
// RUN: %empty-directory(%t)
// RUN: echo "[MyProto]" > %t/protocols.json
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractLiterals.swiftconstvalues -const-gather-protocols-file %t/protocols.json -primary-file %s
// RUN: cat %t/ExtractLiterals.swiftconstvalues 2>&1 | %FileCheck %s
protocol MyProto {}
struct InjectablePropertyStruct : MyProto {
let init1 = Bat(buz: "hello", fuz: 4)
}
public struct Bat {
let buz: String?
let fuz: Int
init(buz: String? = "", fuz: Int = 0) {
self.buz = buz
self.fuz = fuz
}
}
// CHECK: "arguments": [
// CHECK-NEXT: {
// CHECK-NEXT: "label": "buz",
// CHECK-NEXT: "type": "Swift.Optional<Swift.String>",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "hello"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "label": "fuz",
// CHECK-NEXT: "type": "Swift.Int",
// CHECK-NEXT: "valueKind": "RawLiteral",
// CHECK-NEXT: "value": "4"
// CHECK-NEXT: }
// CHECK-NEXT: ]