[swift-evolution] Making capturing semantics of local

Mike Kluev mike.kluev at gmail.com
Thu Oct 26 16:16:15 CDT 2017

On 26 October 2017 at 20:24, David Hart <david at hartbit.com> wrote:

> I don’t see how this makes any sense or be possible:
> * It doesn’t make sense for me because local is not a member function of A.
> * It would cause ambiguity when trying to call another member function
> with the same name as the local function.

in the escaping contexts, "self." is currently required before the instance
members (**).
the idea is to require it before some local functions as well, recursively
analysing what these local functions do (at the compile time).

/* local */ foo() {
    variable = 1


// self is required because the compiler knows what's inside, and if it
were to put the content inline that would be:

// inlining foo pseudo code:
     self.variable = 1

hence the compiler can figure out that in this case "self" is required
before foo()

on the other hand:

/* local */ poo() {
    print("doesnt not capture anything")

here, if compiler were to use poo in the escaping context it would not
require "self." before it.

this decision (whether to require "self." on not) can be on the use side.

(**) FTM, the normal instance methods that do not capture anything may as
well not require "self." before them in escaping contexts:

/* non local */ baz() {
    print("doesn't capture anything")

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171026/a7de4f8a/attachment.html>

More information about the swift-evolution mailing list