-
-
Save sonygod/5211214 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
abstract FunctionReturning<T>(Dynamic) { | |
inline function new (x:Dynamic) this = x; | |
@:from static inline function from0 <T>(x:Void->T):FunctionReturning<T> return new FunctionReturning(x); | |
@:from static inline function from1 <T>(x:Dynamic->T):FunctionReturning<T> return new FunctionReturning(x); | |
@:from static inline function from2 <T>(x:Dynamic->Dynamic->T):FunctionReturning<T> return new FunctionReturning(x); | |
@:from static inline function from3 <T>(x:Dynamic->Dynamic->Dynamic->T):FunctionReturning<T> return new FunctionReturning(x); | |
/* ... */ | |
} | |
class Test { | |
public static function expectReturningInt (x:FunctionReturning<Int>) { | |
} | |
public static function main () { | |
expectReturningInt(function () return 1); // works | |
expectReturningInt(function (z:String) return 1); // works | |
expectReturningInt(function (z:String) return "hi"); // compile time error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment