From e7a6398222beef82114425131b3a226fa70f5fd0 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sun, 1 Dec 2024 18:52:42 -0500 Subject: [PATCH] Always follow aliased imports. Apparently Haxe generates a typedef for these, but other files are prevented from accessing it. --- src/echoes/macro/MacroTools.hx | 22 ++++++++++++++++++---- test/EdgeCaseTest.hx | 13 +++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/echoes/macro/MacroTools.hx b/src/echoes/macro/MacroTools.hx index 7bbc1bf..d792fde 100644 --- a/src/echoes/macro/MacroTools.hx +++ b/src/echoes/macro/MacroTools.hx @@ -32,18 +32,32 @@ class MacroTools { * unless they're marked `@:eager`. Normally, it only follows monomorphs * and `Null` types. */ - public static function followMono(type:Type):Type { + public static function followMono(type:Type, ?importAliases:Array):Type { + if(importAliases == null) { + importAliases = []; + for(i in Context.getLocalImports()) { + switch(i.mode) { + case IAsName(alias): + importAliases.push(alias); + default: + } + } + } + return switch(type) { case null: null; case TMono(_.get() => innerType): - followMono(innerType); + followMono(innerType, importAliases); case TAbstract(_.get() => { name: "Null" }, [innerType]): - followMono(innerType); + followMono(innerType, importAliases); + case TType(_.get() => { name: name, type: innerType }, _) + if(importAliases.contains(name)): + followMono(innerType, importAliases); case TAbstract(_.get() => { type: innerType, meta: meta }, _) | TType(_.get() => { type: innerType, meta: meta }, _) if(meta.has(":eager")): - followMono(innerType); + followMono(innerType, importAliases); default: type; }; diff --git a/test/EdgeCaseTest.hx b/test/EdgeCaseTest.hx index 2c76efc..17262ad 100644 --- a/test/EdgeCaseTest.hx +++ b/test/EdgeCaseTest.hx @@ -1,6 +1,7 @@ package; import Components; +import Components.Color as ColorAlias; import echoes.Echoes; import echoes.Entity; import echoes.System; @@ -140,6 +141,18 @@ class EdgeCaseTest extends Test { #end } + private function testImportAs():Void { + final entity:Entity = new Entity(); + + Assert.notNull(Echoes.getComponentStorage(ColorAlias)); + + entity.add((0x112233:ColorAlias)); + Assert.equals(0x112233, entity.get(Color)); + + entity.remove(Color); + Assert.isFalse(entity.exists(ColorAlias)); + } + private function testNullComponents():Void { final entity:Entity = new Entity();