Files
swift-mirror/test/Constraints/mutating_members.swift
Joe Groff 28fc7b0c80 Sema: Diagnose completely unapplied references to mutating methods.
The currying behavior of method references completely breaks in the face of `inout` semantics, even moreso with exclusivity enforcement, but we failed to diagnose these references in Swift 4 and previous versions. Raise a compatibility warning when these references are found in Swift 4 code, or error in Swift 5 and later. Simplify the partial application logic here slightly too now that standalone functions do not allow currying. Addresses rdar://problem/41361334 | SR-8074.
2018-06-29 21:04:42 -07:00

23 lines
757 B
Swift

// RUN: %target-swift-frontend -typecheck -verify -swift-version 5 %s
struct Foo {
mutating func boom() {}
}
let x = Foo.boom // expected-error{{partial application of 'mutating' method}}
var y = Foo()
let z0 = y.boom // expected-error{{partial application of 'mutating' method}}
let z1 = Foo.boom(&y) // expected-error{{partial application of 'mutating' method}}
func fromLocalContext() -> (inout Foo) -> () -> () {
return Foo.boom // expected-error{{partial application of 'mutating' method}}
}
func fromLocalContext2(x: inout Foo, y: Bool) -> () -> () {
if y {
return x.boom // expected-error{{partial application of 'mutating' method}}
} else {
return Foo.boom(&x) // expected-error{{partial application of 'mutating' method}}
}
}