Skip to content

Commit

Permalink
Always follow aliased imports.
Browse files Browse the repository at this point in the history
Apparently Haxe generates a typedef for these, but other files are prevented from accessing it.
  • Loading branch information
player-03 committed Dec 1, 2024
1 parent 0f8d1e0 commit e7a6398
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/echoes/macro/MacroTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,32 @@ class MacroTools {
* unless they're marked `@:eager`. Normally, it only follows monomorphs
* and `Null<T>` types.
*/
public static function followMono(type:Type):Type {
public static function followMono(type:Type, ?importAliases:Array<String>):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;
};
Expand Down
13 changes: 13 additions & 0 deletions test/EdgeCaseTest.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package;

import Components;
import Components.Color as ColorAlias;
import echoes.Echoes;
import echoes.Entity;
import echoes.System;
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit e7a6398

Please sign in to comment.