mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
For some types which are e.g. ExpressibleByStringLiteral, we may encounter a coerce expression with a compile-time-knowable parameter/sub-expression.
30 lines
961 B
Swift
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"
|