On 04.07.2016 0:47, Anton Zhilin via swift-evolution wrote:
Vladimir.S via swift-evolution <swift-evolution@...> writes:
On 03.07.2016 23:53, Anton Zhilin via swift-evolution wrote:
let x = (Int, Int)(1, 2) //=> (1, 2)
let y = (Int)(1) //=> 1
let z = ()() // error :(
Am I requesting too much from type checker?
As I understand, because () is Void, you can't have anything additional
for
it. It is just Void, like you write 'let z = Void Void'. I.e. only 'let
z =
()' allowed.
In the example, that's how I expect that to parse:
let z = ().init() // just demo, does not compile
I mean, first () is type, and second () is its initializer.
By the way, this is one thing that Void can do, but () cannot.
Are there any others?
I believe in this case () is playing a role of instance of type Void, i.e.
empty tuple. I don't think you can expect ().init()
Also:
func f(_ x: ())->() {}
f(())
//f(Void) // argument passed to call that takes no arguments
And just some fun:
let x1 : Void
//let x2 : Void = Void // cannot convert value of type 'Void.Type' (aka
'().Type') to specified type 'Void' (aka '()')
let x3 : ()
let x4 : () = ()
let x5 : Void = ()
//let x4 : () = Void // cannot convert value of type 'Void.Type' (aka
'().Type') to specified type '()'
print(().dynamicType) // ()
print(().self) // ()
// print("Void.dynamicType = ", Void.dynamicType) // '.dynamicType' is not
allowed after a type name
print(Void.self) // ()
print(().dynamicType == Void.self) // true
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution