Files
swift-mirror/test/SILGen/partial_apply_apply.swift
Slava Pestov c543838854 Sema: Rewrite partial applications into closures
When a method is called with fewer than two parameter lists,
transform it into a fully-applied call by wrapping it in a
closure.

Eg,

Foo.bar => { self in { args... self.bar(args...) } }
foo.bar => { self in { args... self.bar(args...) } }(self)

super.bar => { args... in super.bar(args...) }

With this change, SILGen only ever sees fully-applied calls,
which will allow ripping out some code.

This new way of doing curry thunks fixes a long-standing bug
where unbound references to protocol methods did not work.

This is because such a reference must open the existential
*inside* the closure, after 'self' has been applied, whereas
the old SILGen implementation of curry thunks really wanted
the type of the method reference to match the opened type of
the method.

A follow-up cleanup will remove the SILGen curry thunk
implementation.

Fixes rdar://21289579 and https://bugs.swift.org/browse/SR-75.
2020-03-18 09:29:22 -04:00

25 lines
368 B
Swift

// RUN: %target-swift-frontend -emit-silgen %s
// Make sure an unbound method reference which is then immediately
// called can be SILGen'd correctly.
class C {
func foo(x: Int) {}
}
protocol P {
func foo(x: Int)
}
let c = C()
func doIt(_ c: C, _ p: P ) {
_ = C.foo
_ = C.foo(c)
_ = C.foo(c)(x: 123)
_ = P.foo
_ = P.foo(p)
_ = P.foo(p)(x: 123)
}