Created
March 18, 2020 15:59
-
-
Save nadako/b989a8c6a4c69715e5b2cca41c0d0e19 to your computer and use it in GitHub Desktop.
declaration-site unification check
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
class Point implements UnifyCheck<{x:Int}> { | |
public var x:Int; | |
} | |
class Main { | |
static function main() { | |
} | |
} |
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
@:remove | |
@:autoBuild(UnifyCheckMacro.build()) | |
interface UnifyCheck<T> {} |
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
#if macro | |
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
import haxe.macro.Type; | |
using haxe.macro.Tools; | |
class UnifyCheckMacro { | |
static function build() { | |
var fields = Context.getBuildFields(); | |
var localClass = Context.getLocalClass().get(); | |
for (iface in localClass.interfaces) { | |
switch iface { | |
case {t: _.toString() => "UnifyCheck", params: [type]}: | |
// TODO: handle type params | |
var thisCT = Context.getLocalType().toComplexType(); | |
var unifyCT = type.toComplexType(); | |
fields.push((macro class { | |
extern inline function __unifyCheck__() @:pos(Context.currentPos()) ((null : $thisCT) : $unifyCT); | |
}).fields[0]); | |
break; | |
case _: | |
} | |
} | |
return fields; | |
} | |
} | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment