Files
swift-mirror/test/Sema/object_literals.swift
Chris Willmore d4db635e3d Add object literal syntax and _{Color,Image}LiteralConvertible protocols
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
2015-04-20 12:55:56 +00:00

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 '?'?}}