mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Whenever a variable is written without an initializer, default-initialize the variable (e.g., by calling the default constructor) or produce an error. Fixes <rdar://problem/13134629>, <rdar://problem/11941389>, and the majority of <rdar://problem/11619148>. Missing still is the default initialization of struct members within user-written constructors. That's the last part of <rdar://problem/11619148>. Swift SVN r4974
27 lines
506 B
Swift
27 lines
506 B
Swift
// RUN: %swift %s -verify
|
|
|
|
struct A {
|
|
var i : Int
|
|
constructor(i : Int) { this.i = i }
|
|
}
|
|
|
|
struct B {
|
|
var a : A
|
|
}
|
|
|
|
func locals() {
|
|
var al : A // expected-error{{cannot default-initialize variable of type 'A'}}
|
|
var bl : B // expected-error{{cannot default-initialize variable of type 'B'}}
|
|
}
|
|
|
|
var ag : A // expected-error{{cannot default-initialize variable of type 'A'}}
|
|
var bg : B // expected-error{{cannot default-initialize variable of type 'B'}}
|
|
|
|
struct C {
|
|
var x : (Int, Int)
|
|
}
|
|
|
|
var c : C
|
|
|
|
|