Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
63ce1853f5 | ||
![]() |
f3ddaa6496 | ||
![]() |
f46e49ce66 | ||
![]() |
007c73d58e | ||
![]() |
8c5903833c | ||
![]() |
59d7407d1b | ||
![]() |
0680220a77 | ||
![]() |
acaedc170a |
@@ -9,8 +9,8 @@
|
||||
"contributors": [
|
||||
"back2dos"
|
||||
],
|
||||
"version": "0.21.0",
|
||||
"releasenote": "Expose autocompletion contents. Work around compiler metadata completion issues.",
|
||||
"version": "0.22.0",
|
||||
"releasenote": "Support Haxe 4.2",
|
||||
"tags": [
|
||||
"tink",
|
||||
"macro",
|
||||
|
@@ -23,9 +23,9 @@ class ClassBuilder {
|
||||
target = Context.getLocalClass().get();
|
||||
|
||||
if (fields == null)
|
||||
switch MacroApi.getBuildFields() {
|
||||
fields = switch MacroApi.getBuildFields() {
|
||||
case None: target.pos.error('Impossible to get builds fields now. Possible cause: https://github.com/HaxeFoundation/haxe/issues/9853');
|
||||
case Some(_):
|
||||
case Some(v): v;
|
||||
}
|
||||
|
||||
this.initializeFrom = fields;
|
||||
|
@@ -172,6 +172,9 @@ class Types {
|
||||
#if haxe4
|
||||
isExtern: field.isExtern,
|
||||
isFinal: field.isFinal,
|
||||
#if (haxe >= version("4.2.0-rc.1"))
|
||||
isAbstract: field.isAbstract,
|
||||
#end
|
||||
#end
|
||||
}:ClassField)
|
||||
]);
|
||||
@@ -204,8 +207,19 @@ class Types {
|
||||
case TDynamic(v) if(v != null): getPosition(v);
|
||||
default: Failure('type "$t" has no position');
|
||||
}
|
||||
|
||||
|
||||
|
||||
static public function deduceCommonType(types:Array<Type>):Outcome<Type, Error> {
|
||||
var exprs = types.map(function(t) {
|
||||
var ct = t.toComplex();
|
||||
return macro (null:$ct);
|
||||
});
|
||||
|
||||
return switch (macro $a{exprs}).typeof() {
|
||||
case Success(TInst(_, [v])): Success(v);
|
||||
case Success(_): throw 'unreachable';
|
||||
case Failure(e): Failure(new Error('Unable to deduce common type among $types'));
|
||||
}
|
||||
}
|
||||
|
||||
static public function toString(t:ComplexType)
|
||||
return new Printer().printComplexType(t);
|
||||
|
@@ -65,5 +65,20 @@ class Types extends Base {
|
||||
assertEquals('String', Context.getType('String').toComplex().toString());
|
||||
assertEquals('tink.CoreApi.Noise', Context.getType('tink.CoreApi.Noise').toComplex().toString());
|
||||
}
|
||||
|
||||
function testDeduceCommonType() {
|
||||
function ct2t(ct:ComplexType) return ct.toType().sure();
|
||||
assertEquals('StdTypes.Float', tink.macro.Types.deduceCommonType([(macro:Float), (macro:Int)].map(ct2t)).sure().toComplex().toString());
|
||||
assertEquals('Types.CommonI1', tink.macro.Types.deduceCommonType([(macro:Types.CommonA), (macro:Types.CommonB), (macro:Types.CommonC)].map(ct2t)).sure().toComplex().toString());
|
||||
assertEquals('Types.CommonI2', tink.macro.Types.deduceCommonType([(macro:Types.CommonB), (macro:Types.CommonC)].map(ct2t)).sure().toComplex().toString());
|
||||
// assertEquals('Types.CommonI3', tink.macro.Types.deduceCommonType([(macro:Types.CommonC)].map(ct2t)).sure().toComplex().toString());
|
||||
}
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
interface CommonI1 {}
|
||||
interface CommonI2 {}
|
||||
interface CommonI3 {}
|
||||
class CommonA implements CommonI1 {}
|
||||
class CommonB implements CommonI2 implements CommonI1 {}
|
||||
class CommonC implements CommonI3 implements CommonI2 implements CommonI1 {}
|
Reference in New Issue
Block a user