royale-asjs icon indicating copy to clipboard operation
royale-asjs copied to clipboard

Compiler gets internal error on * in some contexts

Open estanglerbm opened this issue 5 years ago • 6 comments

This line (from existing Flex project):

					var resp : XMLList = XMLList( evt.result.*::response );

causes this compiler error:

didn't find CompilationUnit for * Could not find file for class: * Error: File not found: *

Internal error: java.lang.RuntimeException: Unable to find JavaScript filePath for class: * org.apache.royale.compiler.internal.graph.GoogDepsWriter.addDeps(GoogDepsWriter.java:779)org.apache.royale.compiler.internal.graph.GoogDepsWriter.addDeps(GoogDepsWriter.java:808)org.apache.royale.compiler.internal.graph.GoogDepsWriter.addDeps(GoogDepsWriter.java:808)org.apache.royale.compiler.internal.graph.GoogDepsWriter.addDeps(GoogDepsWriter.java:808)org.apache.royale.compiler.internal.graph.GoogDepsWriter.buildDB(GoogDepsWriter.java:468)org.apache.royale.compiler.internal.graph.GoogDepsWriter.getListOfFiles(GoogDepsWriter.java:115)org.apache.royale.compiler.internal.codegen.mxml.royale.MXMLRoyalePublisher.publish(MXMLRoyalePublisher.java:471)org.apache.royale.compiler.clients.MXMLJSCRoyale.compile(MXMLJSCRoyale.java:442)org.apache.royale.compiler.clients.MXMLJSCRoyale._mainNoExit(MXMLJSCRoyale.java:259)org.apache.royale.compiler.clients.MXMLJSCRoyale.mainNoExit(MXMLJSCRoyale.java:216)org.apache.royale.compiler.clients.MXMLJSC._mainNoExit(MXMLJSC.java:363)org.apache.royale.compiler.clients.MXMLJSC.mainNoExit(MXMLJSC.java:298)org.apache.royale.compiler.clients.MXMLJSC.staticMainNoExit(MXMLJSC.java:256)org.apache.royale.compiler.clients.MXMLJSC.main(MXMLJSC.java:238)

estanglerbm avatar Nov 22 '20 15:11 estanglerbm

I can look into this in a couple of weeks as a compiler issue.

For now, I am hoping we can find a workaround... Firstly (and this would be normal, regardless, with Royale because the XML support also relies quite a bit on the compiler 'knowing' that it is XML) Can you please check what the type (as the compiler could understand it) of evt.result is.

If it is typed as Object or * (untyped), can you please try using an intermediate variable or in-place casting.

e.g. var xml:XML = evt.result as XML; var resp : XMLList = XMLList( xml.*::response );

or maybe var resp : XMLList = XMLList(XML(evt.result).*::response );

This response e4x query is a 'multi-QName' lookup iirc, and I think I did something to get that working in the past for a client project, but I didn't see any unit tests that I added for that specifically, so I can't say for sure it will work, but hopefully it might (fingers crossed).

Let me know how you get on....

greg-dove avatar Nov 24 '20 03:11 greg-dove

Fwiw, I just quickly tested SWF and JS for the following:

var xml:XML = <xml xmlns:cat="cat" xmlns:dog="dog"><cat:response value="cat"/><dog:response value="dog"/><response value="unspaced"/></xml>

var list:XMLList = xml.*::response;

The above gives consistent results between the two. But I was not able to repro that compiler error yet. Hopefully you can get whatever you need working. I will assign this task to myself, but will not get to it for a while, I am afraid.

greg-dove avatar Nov 24 '20 18:11 greg-dove

"evt" is a mx.rpc.events.ResultEvent, so "evt.result" is declared Object but, with e4x, is an XMLList, I believe. It's the result of an HTTPService request. (The XML has ....)

I'll try the possible workarounds.

estanglerbm avatar Nov 25 '20 01:11 estanglerbm

Yes, putting XMLList around "result" is a workaround for the compiler error:

var resp : XMLList = XMLList( (evt.result as XMLList).*::response ); or var resp : XMLList = XMLList( XMLList(evt.result).*::response );

Attached is a simple test case showing the compiler error. TestCompilerStarError.mxml.txt

The issue is doing: Object.*

estanglerbm avatar Nov 30 '20 01:11 estanglerbm

evt.result.*::response

I've never seen namespace syntax used this way. Can * be used as wildcard in E4X to get the child with that name from any namespace?

joshtynjala avatar Dec 01 '20 21:12 joshtynjala

can * be used as wildcard in E4X to get the child with that name from any namespace?

Yes this is how it works. I think I added unit tests to cover this case.

greg-dove avatar Dec 01 '20 21:12 greg-dove