mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Add syntax "[#Color(...)#]" for object literals, to be used by Playgrounds for inline color wells etc. The arguments are forwarded to the relevant constructor (although we will probably change this soon, since (colorLiteralRed:... blue:... green:... alpha) is kind of verbose). Add _ColorLiteralConvertible and _ImageLiteralConvertible protocols, and link them to the new expressions in the type checker. CSApply replaces the object literal expressions with a call to the appropriate protocol witness. Swift SVN r27479
15 lines
509 B
Swift
15 lines
509 B
Swift
// RUN: %target-parse-verify-swift -debug-constraints
|
|
|
|
struct S: _ColorLiteralConvertible {
|
|
init(colorLiteralRed: Float, green: Float, blue: Float, alpha: Float) {}
|
|
}
|
|
|
|
let y: S = [#Color(colorLiteralRed: 1, green: 0, blue: 0, alpha: 1)#]
|
|
|
|
struct I: _ImageLiteralConvertible {
|
|
init?(imageLiteral: String) {}
|
|
}
|
|
|
|
let z: I? = [#Image(imageLiteral: "hello.png")#]
|
|
let z2: I = [#Image(imageLiteral: "hello2.png")#] // expected-error{{value of optional type 'I?' not unwrapped; did you mean to use '!' or '?'?}}
|