Compare commits

..

8 Commits

Author SHA1 Message Date
Juraj Kirchheim
63ce1853f5 Release 0.22.0 2021-02-22 11:46:09 +01:00
Juraj Kirchheim
f3ddaa6496 Merge pull request #33 from haxetink/deduce_common_type
Deduce common base type from a list of types
2020-12-23 09:32:31 +01:00
Kevin Leung
f46e49ce66 Fix haxe3 2020-12-22 17:15:28 +08:00
Kevin Leung
007c73d58e Deduce common base type from a list of types 2020-12-22 16:56:45 +08:00
Juraj Kirchheim
8c5903833c Merge pull request #32 from haxetink/isAbstract
haxe 4.2+ fix
2020-12-20 09:21:31 +01:00
Dan Korostelev
59d7407d1b haxe 4.2+ fix 2020-12-19 22:58:31 +01:00
Juraj Kirchheim
0680220a77 Release 0.21.1 2020-08-20 13:09:07 +02:00
Juraj Kirchheim
acaedc170a Fix issue with build field retrieval. 2020-08-20 13:08:28 +02:00
4 changed files with 36 additions and 7 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -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)
]);
@@ -205,7 +208,18 @@ class Types {
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);

View File

@@ -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
interface CommonI1 {}
interface CommonI2 {}
interface CommonI3 {}
class CommonA implements CommonI1 {}
class CommonB implements CommonI2 implements CommonI1 {}
class CommonC implements CommonI3 implements CommonI2 implements CommonI1 {}