Repository: flex-falcon Updated Branches: refs/heads/develop 2f6f611b1 -> ced58cc23
resolve function calls to instance functions even if masked by local variable but only for legacy codegen Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/2782237d Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/2782237d Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/2782237d Branch: refs/heads/develop Commit: 2782237d58119c21323e031219bc7649584247ff Parents: 1642c4e Author: Alex Harui <[email protected]> Authored: Tue Aug 23 07:38:18 2016 -0700 Committer: Alex Harui <[email protected]> Committed: Tue Aug 23 22:01:59 2016 -0700 ---------------------------------------------------------------------- .../flex/compiler/config/Configuration.java | 5 ++-- .../internal/tree/as/IdentifierNode.java | 31 ++++++++++++++++++++ compiler/src/test/java/as/ASVariableTests.java | 26 ++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2782237d/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java index e5e3613..79e555d 100644 --- a/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java +++ b/compiler/src/main/java/org/apache/flex/compiler/config/Configuration.java @@ -4616,16 +4616,17 @@ public class Configuration // 'compiler.mxml.compatibility-version' option // + public static final int MXML_VERSION_4_7 = 0x04070000; public static final int MXML_VERSION_4_6 = 0x04060000; public static final int MXML_VERSION_4_5 = 0x04050000; public static final int MXML_VERSION_4_0 = 0x04000000; public static final int MXML_VERSION_3_0 = 0x03000000; public static final int MXML_VERSION_2_0_1 = 0x02000001; public static final int MXML_VERSION_2_0 = 0x02000000; - public static final int MXML_CURRENT_VERSION = MXML_VERSION_4_6; + public static final int MXML_CURRENT_VERSION = MXML_VERSION_4_7; public static final int MXML_EARLIEST_MAJOR_VERSION = 3; public static final int MXML_LATEST_MAJOR_VERSION = 4; - public static final int MXML_LATEST_MINOR_VERSION = 6; + public static final int MXML_LATEST_MINOR_VERSION = 7; private int mxml_major = MXML_LATEST_MAJOR_VERSION; private int mxml_minor = MXML_LATEST_MINOR_VERSION; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2782237d/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/IdentifierNode.java ---------------------------------------------------------------------- diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/IdentifierNode.java b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/IdentifierNode.java index 65d8478..da50f5d 100644 --- a/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/IdentifierNode.java +++ b/compiler/src/main/java/org/apache/flex/compiler/internal/tree/as/IdentifierNode.java @@ -37,19 +37,25 @@ import com.google.common.collect.ImmutableSet; import org.apache.flex.abc.semantics.Name; import org.apache.flex.abc.semantics.Nsset; import org.apache.flex.compiler.common.DependencyType; +import org.apache.flex.compiler.config.Configuration; import org.apache.flex.compiler.constants.IASLanguageConstants; import org.apache.flex.compiler.definitions.IClassDefinition; import org.apache.flex.compiler.definitions.IDefinition; import org.apache.flex.compiler.definitions.INamespaceDefinition; import org.apache.flex.compiler.definitions.ITypeDefinition; import org.apache.flex.compiler.definitions.IQualifiers; +import org.apache.flex.compiler.definitions.IVariableDefinition.VariableClassification; import org.apache.flex.compiler.definitions.references.INamespaceReference; import org.apache.flex.compiler.definitions.references.IReference; import org.apache.flex.compiler.definitions.references.ReferenceFactory; import org.apache.flex.compiler.internal.definitions.AmbiguousDefinition; +import org.apache.flex.compiler.internal.definitions.ClassDefinition; +import org.apache.flex.compiler.internal.definitions.ClassDefinitionBase; import org.apache.flex.compiler.internal.definitions.DefinitionBase; +import org.apache.flex.compiler.internal.definitions.FunctionDefinition; import org.apache.flex.compiler.internal.definitions.InterfaceDefinition; import org.apache.flex.compiler.internal.definitions.NamespaceDefinition; +import org.apache.flex.compiler.internal.definitions.VariableDefinition; import org.apache.flex.compiler.internal.projects.FlexProject; import org.apache.flex.compiler.internal.scopes.ASScope; import org.apache.flex.compiler.internal.semantics.PostProcessStep; @@ -384,7 +390,21 @@ public class IdentifierNode extends ExpressionNodeBase implements IIdentifierNod else { if (qualifier == null) + { result = asScope.findProperty(project, name, getDependencyType(), isTypeRef()); + // ASVariableTests_localVarSameNameAsPrivateMethod + if (isLegacyCodegen(project) && result != null && getParent().getNodeID() == ASTNodeID.FunctionCallID && result instanceof VariableDefinition) + { + VariableDefinition varDef = (VariableDefinition)result; + if (varDef.getVariableClassification() == VariableClassification.LOCAL) + { + ClassDefinitionBase cdef = asScope.getContainingClass(); + IDefinition memberResult = asScope.getPropertyFromDef(project, cdef, name, false); + if (memberResult instanceof FunctionDefinition) + result = memberResult; + } + } + } else { result = asScope.findPropertyQualified(project, qualifier, name, getDependencyType(), isTypeRef()); if (result == null && wasMemberRef && baseIsPackage()) @@ -1014,6 +1034,17 @@ public class IdentifierNode extends ExpressionNodeBase implements IIdentifierNod return false; } + public boolean isLegacyCodegen(ICompilerProject project) + { + final Integer compatibilityVersion = ((FlexProject)project).getCompatibilityVersion(); + if (compatibilityVersion == null) + return false; + else if (compatibilityVersion <= Configuration.MXML_VERSION_4_6) + return true; + else + return false; + } + // // Inner types // http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/2782237d/compiler/src/test/java/as/ASVariableTests.java ---------------------------------------------------------------------- diff --git a/compiler/src/test/java/as/ASVariableTests.java b/compiler/src/test/java/as/ASVariableTests.java index f4684fd..b877fcc 100644 --- a/compiler/src/test/java/as/ASVariableTests.java +++ b/compiler/src/test/java/as/ASVariableTests.java @@ -132,6 +132,32 @@ public class ASVariableTests extends ASFeatureTestsBase compileAndRun(source); } + @Test + public void ASVariableTests_localVarSameNameAsPrivateMethod() + { + // all tests can assume that flash.display.Sprite + // flash.system.System and flash.events.Event have been imported + String[] imports = new String[] + { + }; + String[] declarations = new String[] + { + "private function isVertical():Boolean { return false; }", + }; + String[] testCode = new String[] + { + // this threw an exception when the generated code + // tried to call the value of the local var. + // mxmlc will generate a call to the method + // without require a this.isVertical to reference + // the instance method. + "var isVertical:Boolean = isVertical();", + "assertEqual('null', isVertical, false);", + }; + String source = getAS(imports, declarations, testCode, new String[0]); + compileAndRun(source, false, false, false, new String[]{ "-compiler.mxml.compatibility-version=4.6.0" } ); + } + /* public void ASVariableTests_VectorInitializer() {
