Skip to content

Commit 4f1dbdb

Browse files
committed
Test: Add tests for .init calls that should be transformed into assignments
1 parent ad38117 commit 4f1dbdb

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

test/expr/postfix/dot/init_ref_delegation.swift

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,23 @@ func foo<T: C>(_ x: T, y: T.Type) where T: P {
273273
var ci1 = x.init(required: 0) // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}}
274274
var ci2 = x.init(x: 0) // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}}
275275
var ci3 = x.init() // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}}
276-
var ci4 = x.init(proto: "") // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}}
277-
278-
var ci1a = x(required: 0) // expected-error{{cannot call value of non-function type 'T'}}
279-
var ci2a = x(x: 0) // expected-error{{cannot call value of non-function type 'T'}}
280-
var ci3a = x() // expected-error{{cannot call value of non-function type 'T'}}{{15-17=}}
281-
var ci4a = x(proto: "") // expected-error{{cannot call value of non-function type 'T'}}
276+
var ci4 = x.init(proto: "") // expected-error{{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{15-15=type(of: }} {{19-19=)}}
277+
278+
var z = x
279+
z.init(required: 0) // expected-error {{'init' is a member of the type; use assignment to initalize the value instead}} {{4-4= = }}
280+
z.init(x: 0) // expected-error {{'init' is a member of the type; use assignment to initalize the value instead}} {{4-4= = }}
281+
z.init() // expected-error {{'init' is a member of the type; use assignment to initalize the value instead}} {{4-4= = }}
282+
z.init(proto: "") // expected-error {{'init' is a member of the type; use assignment to initalize the value instead}} {{4-4= = }}
283+
284+
var ci1a = z.init(required: 0) // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{16-16=type(of: }} {{20-20=)}}
285+
var ci2a = z.init(x: 0) // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{16-16=type(of: }} {{20-20=)}}
286+
var ci3a = z.init() // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{16-16=type(of: }} {{20-20=)}}
287+
var ci4a = z.init(proto: "") // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{16-16=type(of: }} {{20-20=)}}
288+
289+
var ci1b = x(required: 0) // expected-error{{cannot call value of non-function type 'T'}}
290+
var ci2b = x(x: 0) // expected-error{{cannot call value of non-function type 'T'}}
291+
var ci3b = x() // expected-error{{cannot call value of non-function type 'T'}}{{15-17=}}
292+
var ci4b = x(proto: "") // expected-error{{cannot call value of non-function type 'T'}}
282293

283294
var cm1 = y.init(required: 0)
284295
var cm2 = y.init(x: 0) // expected-error{{'required' initializer}}
@@ -499,3 +510,33 @@ class TestOptionalTrySub : TestOptionalTry {
499510
// expected-note@-1 {{force potentially-failing result with 'try!'}} {{5-9=try!}}
500511
}
501512
}
513+
514+
struct X { init() {} }
515+
516+
struct Y {
517+
func foo(_: X) {}
518+
func asFunctionReturn() -> X {
519+
var a = X()
520+
return a.init() // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{14-14=type(of: }} {{18-18=)}}
521+
}
522+
var x: X
523+
init() {
524+
x.init() // expected-error {{'init' is a member of the type; use assignment to initalize the value instead}} {{6-6= = }}
525+
foo(x.init()) // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{11-11=type(of: }} {{15-15=)}}
526+
}
527+
}
528+
529+
struct Y2 {
530+
var x: X
531+
init() {
532+
x = X()
533+
}
534+
}
535+
536+
struct MultipleMemberAccesses {
537+
var y: Y
538+
init() {
539+
y = Y()
540+
y.x.init() // expected-error {{'init' is a member of the type; use assignment to initalize the value instead}} {{8-8= = }}
541+
}
542+
}

0 commit comments

Comments
 (0)