waneck / testrepo

0 stars 0 forks source link

Issue 1367 - Function type spec. - haxe #1367

Closed waneck closed 11 years ago

waneck commented 11 years ago

[Google Issue #1367 : http://code.google.com/haxe/issues/detail?id=1367] by Andy.onthewings, at 2013-01-07T15:11:38.000Z 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 r5826:

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 2013-01-07T15:19:00.000Z] 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 2013-01-07T15:27:57.000Z] 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 2013-01-07T15:30:25.000Z] 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 2013-01-07T15:36:49.000Z] T->S to T->Void is now allowed in r5827.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2013-01-08T09:40:32.000Z] 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 2013-01-10T10:13:32.000Z] Maybe, but is that a solution or a workaround?

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2013-01-12T15:40:27.000Z] 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 2013-01-13T21:06:38.000Z] I'll handle it during Reflect.hx specification then.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2013-01-18T20:40:31.000Z] This issue was closed by revision r5894.