Skip to content

Commit 652b58b

Browse files
committed
[TypeChecker] NFC: Add a couple of additional tests for invalid partial apply
Verify that invalid partial apply is detected if base of the mutating method if unknown upfront.
1 parent 174fd14 commit 652b58b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

test/Constraints/mutating_members.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-swift-frontend -typecheck -verify -swift-version 5 %s
22

3+
protocol P {}
4+
35
struct Foo {
46
mutating func boom() {}
57
}
@@ -20,3 +22,15 @@ func fromLocalContext2(x: inout Foo, y: Bool) -> () -> () {
2022
}
2123
}
2224

25+
func bar() -> P.Type { fatalError() }
26+
func bar() -> Foo.Type { fatalError() }
27+
28+
_ = bar().boom // expected-error{{partial application of 'mutating' method}}
29+
_ = bar().boom(&y) // expected-error{{partial application of 'mutating' method}}
30+
_ = bar().boom(&y)() // ok
31+
32+
func foo(_ foo: Foo.Type) {
33+
_ = foo.boom // expected-error{{partial application of 'mutating' method}}
34+
_ = foo.boom(&y) // expected-error{{partial application of 'mutating' method}}
35+
_ = foo.boom(&y)() // ok
36+
}

test/Constraints/mutating_members_compat.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-swift-frontend -typecheck -verify -swift-version 4 %s
22

3+
protocol P {}
4+
35
struct Foo {
46
mutating func boom() {}
57
}
@@ -20,3 +22,15 @@ func fromLocalContext2(x: inout Foo, y: Bool) -> () -> () {
2022
}
2123
}
2224

25+
func bar() -> P.Type { fatalError() }
26+
func bar() -> Foo.Type { fatalError() }
27+
28+
_ = bar().boom // expected-warning{{partial application of 'mutating' method}}
29+
_ = bar().boom(&y) // expected-error{{partial application of 'mutating' method}}
30+
_ = bar().boom(&y)() // ok
31+
32+
func foo(_ foo: Foo.Type) {
33+
_ = foo.boom // expected-warning{{partial application of 'mutating' method}}
34+
_ = foo.boom(&y) // expected-error{{partial application of 'mutating' method}}
35+
_ = foo.boom(&y)() // ok
36+
}

0 commit comments

Comments
 (0)