Files
swift-mirror/test/ConstExtraction/ExtractCoerce.swift
Artem Chikin aa70ac7e52 [Compile Time Constant Extraction] Extract explicit cast property init values
For some types which are e.g. ExpressibleByStringLiteral, we may encounter a coerce expression with a compile-time-knowable parameter/sub-expression.
2023-02-21 09:28:45 -08:00

30 lines
961 B
Swift

// 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
struct CoercableThing : ExpressibleByStringLiteral {
let thing: String
public init(unicodeScalarLiteral value: String) {
self.init(stringLiteral: value)
}
init(stringLiteral: String) {
self.thing = stringLiteral
}
}
protocol MyProto {}
public struct TestStruct : MyProto {
let foo: CoercableThing = "foo"
let bar: CoercableThing = CoercableThing("bar")
}
// CHECK: "label": "foo",
// CHECK: "valueKind": "RawLiteral",
// CHECK: "value": "foo"
// CHECK: "label": "bar",
// CHECK: "valueKind": "RawLiteral",
// CHECK: "value": "bar"