mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This is something I noticed by inspection while working on <https://bugs.swift.org/browse/SR-75>. Inside a static method, 'self' is a metatype value, so 'self.instanceMethod' produces an unbound reference of type (Self) -> (Args...) -> Results. You might guess that 'super.instanceMethod' can similarly be used to produce an unbound method reference that calls the superclass method given any 'self' value, but unfortunately it doesn't work. Instead, 'super.instanceMethod' would produce the same result as 'self.instanceMethod'. Maybe we can implement this later, but for now, let's just diagnose the problem. Note that partially-applied method references with 'super.' -- namely, 'self.staticMethod' inside a static context, or 'self.instanceMethod' inside an instance context, continue to work as before. They have the type (Args...) -> Result; since the self value has already been applied we don't hit the representational issue.
37 lines
1.3 KiB
Swift
37 lines
1.3 KiB
Swift
// RUN: %target-swift-frontend -typecheck -verify -swift-version 5 %s
|
|
|
|
protocol P {}
|
|
|
|
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}}
|
|
}
|
|
}
|
|
|
|
func bar() -> P.Type { fatalError() }
|
|
func bar() -> Foo.Type { fatalError() }
|
|
|
|
_ = bar().boom // expected-error{{partial application of 'mutating' method}}
|
|
_ = bar().boom(&y) // expected-error{{partial application of 'mutating' method}}
|
|
_ = bar().boom(&y)() // expected-error{{partial application of 'mutating' method}}
|
|
|
|
func foo(_ foo: Foo.Type) {
|
|
_ = foo.boom // expected-error{{partial application of 'mutating' method}}
|
|
_ = foo.boom(&y) // expected-error{{partial application of 'mutating' method}}
|
|
_ = foo.boom(&y)() // expected-error{{partial application of 'mutating' method}}
|
|
}
|