Files
swift-mirror/test/Parse/new_array.swift
Joe Groff 911929f1dd Parse and type check initializer closures after 'new T[n]' exprs.
Require that either T be default constructible or that the user provide a closure that maps indices to initial values. We don't actually call the closure yet to initialize the array; that's blocked on function abstraction difference <rdar://problem/13251236>.

Swift SVN r8801
2013-10-01 05:12:54 +00:00

23 lines
848 B
Swift

// RUN: %swift -parse -verify %s
struct DefaultConstructible {
constructor() {}
constructor(x:Int) {}
constructor(x:Int, y:String) {}
}
struct NotDefaultConstructible {
constructor(x:Int) {}
constructor(x:Int, y:String) {}
}
var a = new DefaultConstructible[10]
var b = new DefaultConstructible[10] { DefaultConstructible($0) }
var c = new DefaultConstructible[10] { NotDefaultConstructible($0) } // expected-error{{}}
var d = new DefaultConstructible[10] { DefaultConstructible(22, $0) } // expected-error{{}}
var e = new NotDefaultConstructible[10] // expected-error{{}}
var f = new NotDefaultConstructible[10] { NotDefaultConstructible($0) }
var g = new NotDefaultConstructible[10] { DefaultConstructible($0) } // expected-error{{}}
var h = new NotDefaultConstructible[10] { NotDefaultConstructible(22, $0) } // expected-error{{}}