haxe icon indicating copy to clipboard operation
haxe copied to clipboard

[jvm] Cannot import class that imports non-existant class

Open LordMZTE opened this issue 1 year ago • 2 comments

When specifying an external java library using --java-lib, Haxe will fail to compile the Haxe source if it references a class from the external library that imports another class which isn't found in the compile-time classpath.

This is valid on the Java side, as a library that optionally depends on another might have imports for classes of that library. This only results in a runtime error if the imported class is used at runtime (meaning, that references merely existing is unproblematic), thus such Haxe code should compile.

LordMZTE avatar Aug 24 '24 13:08 LordMZTE

Hmm, I think in practice this would mean that we simply ignore errors (and thus modules) which are loaded from an external library and contain references to non-existing types.

My biggest concern is error message quality because in that case we'd get a "Type not found A" error if A exists but references B which doesn't exist. So a cleaner approach would be to mark modules as "unusable" or something, and then error only if they are actually used. But that itself is challenging too because modules can be loaded for all sorts of reasons.

In that light I'm inclined to state that this simply isn't supported in Haxe.

Simn avatar Aug 24 '24 15:08 Simn

Why not allow loading A if B doesn't exist regardless? The class is perfectly usable from the outside, this is how it works in Java, too. Haxe also doesn't really need to care about B here, as Haxe code only uses A (and A does not contain B in its public API, that would result in a runtime error on the JVM once A is loaded if B is not present, as far as I know).

LordMZTE avatar Aug 24 '24 17:08 LordMZTE

This isn't about allowing something or not, it's about dealing with a situation that the compiler usually doesn't support, i.e. references to types that don't exist. This adds a level of complexity that I don't want to deal with, especially given that this hasn't come up before. I think a better solution would be a tool that processes the bytecode to filter out any such references, but that's outside the scope of the compiler.

Simn avatar Oct 16 '24 08:10 Simn