Skip to content

Commit a13dba9

Browse files
committed
Test: Add tests for .init called on mutable value inside operator
1 parent 8ad51b2 commit a13dba9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

test/expr/postfix/dot/init_ref_delegation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,14 @@ class TestOptionalTrySub : TestOptionalTry {
513513

514514
struct X { init() {} }
515515

516+
func +(lhs: X, rhs: X) -> X { return lhs }
517+
func testInsideOperator(x: X) {
518+
x.init() + x // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{5-5=type(of: }} {{9-9=)}}
519+
x + x.init() // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{9-9=type(of: }} {{13-13=)}}
520+
x.init() + x.init() // expected-error {{'init' is a member of the type; use 'type(of: ...)' to initialize a new object of the same dynamic type}} {{5-5=type(of: }} {{9-9=)}}
521+
// expected-error@-1 {{'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=)}}
522+
}
523+
516524
struct Y {
517525
var x: X
518526
let x2: X

0 commit comments

Comments
 (0)