Commit Graph

4 Commits

Author SHA1 Message Date
Abdul Ajetunmobi
f8c737b1ec SR-13976: Improve compiler error message: "partial application of ‘mutating’ method is not allowed” 2021-10-06 19:59:09 +01:00
Slava Pestov
019452f9af Sema: Diagnose unbound method references on 'super.'
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.
2020-02-27 17:28:23 -05:00
Pavel Yaskevich
652b58b415 [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.
2019-01-25 14:18:11 -08:00
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