Fixing bug with static function resolution #56
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ensures the initial class scope is at the top of the stack so that it is popped first; allows overriding of
apply
andcall
etc where these are present in the scope stack due to Class deriving from FunctionI had noticed that I kept on getting errors when transpiling code that used
ExternalInterface.call
, where the JavaScript ended up just as:rather than the calls to
ExternalInterface.available
oraddCallback
, which were correctly emitted as:Having looked into this, there's a scope resolution where the compiler is looking for a definition of "call" within the current scope - at the top of which is the ExternalInterface class, and it should then expand the search to the base classes. As a static type, the base of ExternalInterface is Class, the base of Class is Function, and the base of Function is Object. However, in the
StaticTypeIterator
initilalizer, the code was adding the initial scope (ExternalInterface) to the stack and then adding the built-in Class definition; this is the wrong order, since the iterator'snext
method pops the most recent addition first.So to correct this, we push the
Class
type and then theinitialType
(ExternalInterface in my case) is added on top. Note the "skipThis" flag which affected the behaviour; checking for this here simplifies it a little bit, as the flag (if used?) indicates that the initialType should be ignored and would have been added to the visited list rather than onto our stack. The old implementation of this - just callingnext()
ifskipThis
was true - would have exposed the bug, as the call tonext()
would have removed the Class definition...