Skip to content

Instantly share code, notes, and snippets.

@Simn
Last active August 29, 2015 14:04
Show Gist options
  • Save Simn/7e85657a40d6d2749419 to your computer and use it in GitHub Desktop.
Save Simn/7e85657a40d6d2749419 to your computer and use it in GitHub Desktop.
@:genericBuild DeclType
@: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);
}
}
}
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