You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2016/08/24 05:02:35 UTC

[4/7] git commit: [flex-falcon] [refs/heads/develop] - detect calls to nonFunctions

detect calls to nonFunctions


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/1642c4ea
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/1642c4ea
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/1642c4ea

Branch: refs/heads/develop
Commit: 1642c4ea15225eb972772473fafad459bf64c1a9
Parents: 7f3621a
Author: Alex Harui <ah...@apache.org>
Authored: Mon Aug 22 07:47:26 2016 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Aug 23 22:01:59 2016 -0700

----------------------------------------------------------------------
 .../semantics/MethodBodySemanticChecker.java    | 16 ++++++++
 .../problems/CallNonFunctionProblem.java        | 42 ++++++++++++++++++++
 compiler/src/test/java/as/ASVariableTests.java  | 26 ++++++++++++
 3 files changed, 84 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1642c4ea/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java b/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
index c91fcf4..04eb040 100644
--- a/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
+++ b/compiler/src/main/java/org/apache/flex/compiler/internal/semantics/MethodBodySemanticChecker.java
@@ -850,6 +850,22 @@ public class MethodBodySemanticChecker
             FunctionDefinition func = (FunctionDefinition)def;
             checkFormalsVsActuals(iNode, func, actuals);
         }
+        else if ( def instanceof VariableDefinition )
+        {
+            VariableDefinition varDef = (VariableDefinition)def;
+            IDefinition varType = varDef.resolveType(project);
+            if (varType == null || // Null here means the ANY_TYPE
+                    varType.equals(project.getBuiltinType(BuiltinType.FUNCTION)) ||
+                    varType.equals(project.getBuiltinType(BuiltinType.OBJECT)) ||
+                    varType.equals(project.getBuiltinType(BuiltinType.ANY_TYPE)))
+            {
+                // assume it can be called
+            }
+            else
+            {
+                addProblem(new CallNonFunctionProblem(iNode, method_binding.getName().getBaseName()));
+            }
+        }
         else if ( def == project.getBuiltinType(BuiltinType.ARRAY) )
         {
             // Warn about calling Array as a function because developers

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1642c4ea/compiler/src/main/java/org/apache/flex/compiler/problems/CallNonFunctionProblem.java
----------------------------------------------------------------------
diff --git a/compiler/src/main/java/org/apache/flex/compiler/problems/CallNonFunctionProblem.java b/compiler/src/main/java/org/apache/flex/compiler/problems/CallNonFunctionProblem.java
new file mode 100644
index 0000000..50f075c
--- /dev/null
+++ b/compiler/src/main/java/org/apache/flex/compiler/problems/CallNonFunctionProblem.java
@@ -0,0 +1,42 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.problems;
+
+import org.apache.flex.compiler.tree.as.IASNode;
+
+/**
+ *  Strict semantics diagnostic emitted when the method body
+ *  semantic checker detects a call to function that isn't of type function.
+ */
+public final class CallNonFunctionProblem extends StrictSemanticsProblem
+{
+    public static final String DESCRIPTION =
+        "Call to ${methodName} is not a function.";
+
+    public static final int errorCode = 1181;
+
+    public CallNonFunctionProblem(IASNode node, String methodName)
+    {
+        super(node);
+        this.methodName = methodName;
+    }
+    
+    public final String methodName;
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/1642c4ea/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 10314d9..f4684fd 100644
--- a/compiler/src/test/java/as/ASVariableTests.java
+++ b/compiler/src/test/java/as/ASVariableTests.java
@@ -106,6 +106,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);
+    }
+
     /*
     public void ASVariableTests_VectorInitializer()
     {