Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dodge HaxeFoundation/Haxe#11338 by also looking at imported types #62

Closed
wants to merge 3 commits into from

Conversation

kLabz
Copy link
Contributor

@kLabz kLabz commented Dec 3, 2024

@yuxiaomao
Copy link
Contributor

Seems good now for Shiro's projects.

@kLabz
Copy link
Contributor Author

kLabz commented Dec 3, 2024

What is the minimum Haxe version supported by domkit? This PR uses a Haxe 4.3.0 feature (?? operator)

@ncannasse
Copy link
Member

Can you tell me which cases this is trying to solve ? It seems a bit overly complex.

@Simn
Copy link

Simn commented Jan 17, 2025

The problem is that domkit abused HaxeFoundation/haxe#9150 by importing some.ComponentCollection to make its types available as some.Component. This no longer works after HaxeFoundation/haxe#11338, so a different solution is needed.

@kLabz
Copy link
Contributor Author

kLabz commented Jan 17, 2025

There are more subtlety that I need to list and detail after reconstructing the failing cases (the ones from when I opened this PR but also the ones I found later that this PR didn't fix).

@kLabz
Copy link
Contributor Author

kLabz commented Jan 17, 2025

Can repro the initial issue with dune:

 ERROR  src/ui/GameUI.hx:58: characters 4-21

 58 |   <spectator-top-bar/>
    |    ^^^^^^^^^^^^^^^^^
    | Could not load component 'spectator-top-bar'

Init macros add this as components path:

domkit.Macros.registerComponentsPath("ui.hud.$UI");

Module src/ui/hud/SpectatorUI.hx also defines component SpectatorTopBarUI which we want to resolve here. This used to work because there is import ui.hud.SpectatorUI in GameUI.hx, so SpectatorUI module is loaded and SpectatorTopBarUI could be resolved through ui.hud.SpectatorTopBarUI.

We cannot resolve ui.hud.SpectatorTopBarUI directly anymore, but SpectatorTopBarUI is available locally thanks to the import. This is what Context.resolveComplexType handles here (it also compares packages to be sure this is not resolving some unrelated component that would have the same name).


There is also this case:

domkit.Macros.registerComponentsPath("h2d.domkit.BaseComponents.$Comp");

For which I added the name vs sub handling.


As to why I replaced Context.getType(path) with Context.resolveType(TPath(tpath), pos); there.. I'm not sure anymore tbh, my current guess is that it's mostly a remnant of the early stages of that PR, where I was manipulating a type path instead of a string. I think the two actual differences there are ParamSpawnMonos vs ParamNormal and exceptions being String vs Dynamic (but it was already catching Dynamic anyway) edit: that part of the docs seems wrong.

@kLabz
Copy link
Contributor Author

kLabz commented Jan 17, 2025

If we don't care about checking packages there (should be very niche issue, but still technically possible), this can be reduced to:

var path = p.split("$").join(uname);
// Note: might be nice to expose such a tool (dotpath => type path) in our macro API, if that's not already available..
var tpath = {pack: [], name: "", sub: null};
for (p in path.split(".")) {
	if (p.charCodeAt(0) >= 'a'.code && p.charCodeAt(0) <= 'z'.code) {
		tpath.pack.push(p);
	} else {
		if (tpath.name == "") tpath.name = p;
		else if (tpath.sub == null) tpath.sub = p;
	}
}

var t = try {
	Context.getType(path);
} catch(e:Dynamic) {
	try Context.getType(tpath.sub ?? tpath.name) catch(e:Dynamic) continue;
}

@ncannasse
Copy link
Member

@kLabz thanks for the description of the issue in relation to the actual code involved.
However I think this should be resolved by having "$" component path registered so when we have an import we can load its components using the name itself. In that case we wouldn't need to change the domkit code at all ?
Can you confirm that @yuxiaomao ?

@kLabz
Copy link
Contributor Author

kLabz commented Jan 18, 2025

That wouldn't work here either because $ would resolve to SpectatorTopBar, not SpectatorTopBarUI

@ncannasse
Copy link
Member

ncannasse commented Jan 18, 2025 via email

@kLabz
Copy link
Contributor Author

kLabz commented Jan 18, 2025

Seems to work indeed for dune 👍

@kLabz kLabz closed this Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants