Skip to content

Instantly share code, notes, and snippets.

@SmilyOrg
Last active August 29, 2015 13:59
Show Gist options
  • Save SmilyOrg/10593151 to your computer and use it in GitHub Desktop.
Save SmilyOrg/10593151 to your computer and use it in GitHub Desktop.
Haxe compiler Array<FunctionArg> @:optional unintuitive typing?
class Test {
static function main() {
var args = [{ name: "abc", type: null }]; // FAILS
//var args = [{ name: "abc", type: null, opt: false, value: null }]; // WORKS
//var args:Array<FunctionArg> = [{ name: "abc", type: null }]; // WORKS
(args:Array<haxe.macro.Expr.FunctionArg>);
/*
Compiler throws the following error for the first option:
test/Test.hx:8: characters 3-7 : Array<{ type : Null<haxe.macro.ComplexType>, name : String }> should be Array<haxe.macro.FunctionArg>
test/Test.hx:8: characters 3-7 : Type parameters are invariant
test/Test.hx:8: characters 3-7 : { type : Null<haxe.macro.ComplexType>, name : String } should be haxe.macro.FunctionArg
test/Test.hx:8: characters 3-7 : { type : Null<haxe.macro.ComplexType>, name : String } should be { ?value : Null<haxe.macro.Expr>, type : Null<haxe.macro.ComplexType>, ?opt : Bool, name : String }
test/Test.hx:8: characters 3-7 : { type : Null<haxe.macro.ComplexType>, name : String } has no field opt
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment