tink_await icon indicating copy to clipboard operation
tink_await copied to clipboard

Allow transforming local function without putting restriction on the wrapping function

Open kevinresol opened this issue 8 years ago • 8 comments

I would like to do this:

@:await
class Await {
  public function wrapper() {
    @:async function local() {
      // ...
    }
  }
}

Note that wrapper is not tagged by @:await nor @:async

kevinresol avatar Jun 09 '17 06:06 kevinresol

That means we'd have to check all expressions of every method to see if it contains the metadata. But if this is something you regularly need, we could enable it behind a flag and see how it goes?

benmerckx avatar Jun 09 '17 06:06 benmerckx

Or introducing another meta besides await and async which is used to only indicate there are something to get transformed inside?

kevinresol avatar Jun 09 '17 06:06 kevinresol

That's what @:await on a method is already there for?

@:await
class Await {
	@:await function wrapper() {
		@:async function local() {
			return @:await something();
		}
		// ... use local ...
	}
}

benmerckx avatar Jun 09 '17 08:06 benmerckx

Oh I thought @:await forces the function to return Void. If that's not the case, this can be closed.

kevinresol avatar Jun 09 '17 08:06 kevinresol

It doesn't :) It works as you proposed:

to only indicate there are something to get transformed inside

I've added a test here, but let's keep this open so I can add some info in the docs. I didn't before because I wasn't sure about the name (as @:await now has a different meaning on either class/method/expr). But after this time I don't think I'm going to come up with something better :)

benmerckx avatar Jun 09 '17 08:06 benmerckx

Oh, wait I spoke too soon. A method marked @:await does force its return type to Void, but only once an @:await expression is used. I need a minute to check that restriction..

benmerckx avatar Jun 09 '17 08:06 benmerckx

So, this works:

@:await function wrapper() {
    @:async function local() {
        return @:await something();
    }
    return whatever;
}

But, this doesn't:

@:await function wrapper() {
    @:await something();
    return whatever;
}

Because it cannot get transformed to something that makes sense.

benmerckx avatar Jun 09 '17 09:06 benmerckx

Ok, then great. And the Void case is very understandable. Thanks.

kevinresol avatar Jun 09 '17 14:06 kevinresol