Skip to content

Instantly share code, notes, and snippets.

@frabbit
Last active December 15, 2015 04:49
Show Gist options
  • Save frabbit/5204038 to your computer and use it in GitHub Desktop.
Save frabbit/5204038 to your computer and use it in GitHub Desktop.
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