From 2471637905732feb6364e8d38bace0e8613fa6c6 Mon Sep 17 00:00:00 2001 From: Juraj Kirchheim Date: Thu, 6 Apr 2023 06:41:28 +0000 Subject: [PATCH] Fix tests for 4.3 and make use of getConfiguration. --- haxe_libraries/tink_core.hxml | 6 +++--- src/tink/MacroApi.hx | 21 ++++++++++++++------- src/tink/macro/Types.hx | 2 +- tests/Base.hx | 4 +++- tests/Positions.hx | 4 +--- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/haxe_libraries/tink_core.hxml b/haxe_libraries/tink_core.hxml index 98d5369..37a0d96 100644 --- a/haxe_libraries/tink_core.hxml +++ b/haxe_libraries/tink_core.hxml @@ -1,3 +1,3 @@ -# @install: lix --silent download "gh://github.com/haxetink/tink_core#abee932c4e724517090238b6527eac28874c0354" into tink_core/1.27.1/github/abee932c4e724517090238b6527eac28874c0354 --cp ${HAXE_LIBCACHE}/tink_core/1.27.1/github/abee932c4e724517090238b6527eac28874c0354/src --D tink_core=1.27.1 \ No newline at end of file +# @install: lix --silent download "haxelib:/tink_core#2.1.0" into tink_core/2.1.0/haxelib +-cp ${HAXE_LIBCACHE}/tink_core/2.1.0/haxelib/src +-D tink_core=2.1.0 \ No newline at end of file diff --git a/src/tink/MacroApi.hx b/src/tink/MacroApi.hx index 2f934fb..db23b34 100644 --- a/src/tink/MacroApi.hx +++ b/src/tink/MacroApi.hx @@ -33,15 +33,22 @@ class MacroApi { static var MAIN_CANDIDATES = ['-main', '-x', '--run']; static public function getMainClass():Option { - var args = Sys.args(); - - for (c in MAIN_CANDIDATES) - switch args.indexOf(c) { - case -1: - case v: return Some(args[v+1]); + #if (haxe_ver >= 4.3) + return switch haxe.macro.Compiler.getConfiguration().mainClass { + case null: None; + case p: Some(p.pack.concat([p.name]).join('.')); } + #else + var args = Sys.args(); - return None; + for (c in MAIN_CANDIDATES) + switch args.indexOf(c) { + case -1: + case v: return Some(args[v+1]); + } + + return None; + #end } @:persistent static var idCounter = 0; diff --git a/src/tink/macro/Types.hx b/src/tink/macro/Types.hx index 709daee..86c85ab 100644 --- a/src/tink/macro/Types.hx +++ b/src/tink/macro/Types.hx @@ -214,7 +214,7 @@ class Types { static public function deduceCommonType(types:Array):Outcome { var exprs = types.map(function(t) { var ct = t.toComplex(); - return macro (null:$ct); + return macro (cast null:$ct); }); return switch (macro $a{exprs}).typeof() { diff --git a/tests/Base.hx b/tests/Base.hx index 7a296ed..a154181 100644 --- a/tests/Base.hx +++ b/tests/Base.hx @@ -29,7 +29,9 @@ abstract PhysicalType(Either, Enum>) { } //TODO: this helper should go somewhere class Base extends TestCase { - + function stringCompare(v1:A, v2:A, ?pos) + assertEquals(Std.string(v1), Std.string(v2), pos); + function fail(msg:String, ?c : PosInfos) { currentTest.done = true; currentTest.success = false; diff --git a/tests/Positions.hx b/tests/Positions.hx index ca957b5..4417446 100644 --- a/tests/Positions.hx +++ b/tests/Positions.hx @@ -6,8 +6,6 @@ import haxe.macro.Expr; using tink.MacroApi; class Positions extends Base { - function stringCompare(v1:A, v2:A) - assertEquals(Std.string(v1), Std.string(v2)); function testSanitize() { var p:Position = null; @@ -19,6 +17,6 @@ class Positions extends Base { function testBlank() { var p:Position = null; var t = p.makeBlankType(); - stringCompare('TMono()', cast t.toType().sure()); + stringCompare('TMono()', cast t.toType().sure().reduce()); } } \ No newline at end of file