Last active
December 19, 2015 12:48
-
-
Save nadako/5957084 to your computer and use it in GitHub Desktop.
Type inference fail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-cp src | |
-main Main | |
-swf bin/Main.swf | |
-cmd start bin/Main.swf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
class Main | |
{ | |
public function new(root) | |
{ | |
root.addEventListener(flash.events.Event.ENTER_FRAME, onEnterFrame); | |
} | |
function onEnterFrame(_) | |
{ | |
} | |
static function main() | |
{ | |
new Main(flash.Lib.current); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src/Main.hx:16: characters 11-28 : flash.display.MovieClip should be { addEventListener : String -> (_ : Unknown<1> -> Void) -> Unknown<0> } | |
src/Main.hx:16: characters 11-28 : Invalid type for field addEventListener : | |
src/Main.hx:16: characters 11-28 : type : String -> listener : (Dynamic -> Void) -> ?useCapture : Bool -> ?priority : Int -> ?useWeakReference : Bool -> Void should be String -> (_ : Unknown<1> -> Void) -> Unknown<0> | |
src/Main.hx:16: characters 11-28 : For function argument 'root' |
[15:00:59] <Simn> It's the optional arguments.
[15:02:39] <nadako> hm, yeah it works if I specify values for optional arguments in the addEventListener call without specifying type
[15:03:58] <Simn> yea, there's a reason for that
[15:04:14] <nadako> Though I wonder why it's not possible to match the signature that way. Does it create any ambiguity? Sorry I'm kinda new to the whole type inference thing :)
[15:04:57] <Simn> It has to do with how code is generated. Some platforms require optional arguments to be padded with null, which only works if the compile-time knows about them.
[15:05:33] <Simn> You cannot call a foo(?opt) function as foo() on all targets, so the compiler has to deal with that in some way.
[15:06:07] <nadako> Hm, that makes sense. Thanks! Though maybe then compiler could give more meaningful error message :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works well if I specify a type for the "root" argument of the "new" function explicitly. I wonder if it's because optional arguments or I just don't understand something.