Last active
August 29, 2015 14:04
-
-
Save Simn/7e85657a40d6d2749419 to your computer and use it in GitHub Desktop.
@:genericBuild DeclType
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
@:genericBuild(MyMacro.infer()) | |
class DeclType<Const> { } | |
class Main { | |
static function main() { | |
var values = [for (i in 0...10) { i : i, hello: true }]; | |
var list = []; | |
function example(v:DeclType<[values[0]]>) { | |
trace(v.i); | |
list.push(v); | |
} | |
for (v in list) { | |
trace(v.i, v.hello); | |
} | |
} | |
} |
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
import haxe.macro.Expr; | |
import haxe.macro.Context; | |
import haxe.macro.Type; | |
class MyMacro { | |
macro static function infer():Type { | |
switch (Context.getLocalType()) { | |
case TInst(_, [TInst(_.get() => {kind: KExpr(macro $a{e})}, _)]): | |
return Context.typeof(e[0]); | |
case _: | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment