HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.18k stars 655 forks source link

Issue 1367 - Function type spec. - haxe #1367

Closed waneck closed 11 years ago

waneck commented 11 years ago

[Google Issue #1367 : https://code.google.com/p/haxe/issues/detail?id=1367] by Andy.onthewings, at 07/01/2013, 15:11:38 How Haxe is treating function types is changed since 2.10 release, and it is affecting quite a few libs I'm using (HaxePunk, hxhsl etc).

I cannot find related unit test in svn, and I guess it is good to include the following.

Compile in 2.10, but not in 801a6c4aae4cda60504c320e234ab94410037641:

var a:Void->Void = function():Dynamic return 0;
var a:Void->Dynamic = function():Void {}

Never compile, but I would like to confirm they are really disallowed (hoping not):

var a:Void->Void = function():Int return 0;
var a:Void->Void = function(a = 0):Void {}
var a:Void->Void = function(?a = 0):Void {}
waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 07/01/2013, 15:19:00] The following is now forbidden since Void is a no-value while Dynamic except a value. var a:Void->Dynamic = function():Void {}

These two were not working with 2.10 I think (should be giving explicit error such as "cannot erase optional parameter") var a:Void->Void = function(a = 0):Void {} var a:Void->Void = function(?a = 0):Void {}

As for the erasure of return type, in both of these cases : var a:Void->Void = function():Dynamic return 0; var a:Void->Void = function():Int return 0;

I think they should be allowed again since it shouldn't have any bad impact to simply ignore the returned value.

waneck commented 11 years ago

[comment from Andy.onthewings, published at 07/01/2013, 15:27:57] Great, thanks!

One problem, Reflect.makeVarArgs expects a Array->Dynamic, but we cannot use it with a Array->Void now. Maybe adding a type param would be needed? e.g.

static function makeVarArgs<T>( f : Array<Dynamic> -> T ) : Dynamic
waneck commented 11 years ago

[comment from Andy.onthewings, published at 07/01/2013, 15:30:25] Oh, maybe even better:

static function makeVarArgs<A,T>( f : Array<A> -> T ) : Dynamic
waneck commented 11 years ago

[comment from si...@haxe.org, published at 07/01/2013, 15:36:49] T->S to T->Void is now allowed in 757624c9e86f9a28fbaf14901964e5d76cf22446.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 08/01/2013, 09:40:32] Thanks for noticing makeVarArgs bug. @ Simon : maybe adding an overload here will help ?

waneck commented 11 years ago

[comment from si...@haxe.org, published at 10/01/2013, 10:13:32] Maybe, but is that a solution or a workaround?

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 12/01/2013, 15:40:27] Seems like a solution to me : makeVarArgs is quite particular in the sense that the Dynamic returned value is never actually used, since it returns a new function

waneck commented 11 years ago

[comment from si...@haxe.org, published at 13/01/2013, 21:06:38] I'll handle it during Reflect.hx specification then.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 18/01/2013, 20:40:31] This issue was closed by revision 141cab1f55d1165d91b81ae1e508d5462f1c4260.