This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new e8557a3  compiler: added missing warning for function parameters that 
don't have a type declaration, similar to the return type or variables
e8557a3 is described below

commit e8557a39f6f4d7ca219b24c9f6552651382191d6
Author: Josh Tynjala <joshtynj...@apache.org>
AuthorDate: Tue Dec 18 15:00:11 2018 -0800

    compiler: added missing warning for function parameters that don't have a 
type declaration, similar to the return type or variables
    
    The Flex compiler had a warning for this, and the Royale compiler should too
---
 .../ParameterHasNoTypeDeclarationProblem.java      | 46 ++++++++++++++++++++++
 .../as/codegen/InterfaceDirectiveProcessor.java    |  2 +
 .../semantics/MethodBodySemanticChecker.java       |  1 +
 .../compiler/internal/semantics/SemanticUtils.java | 31 +++++++++++++++
 4 files changed, 80 insertions(+)

diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/problems/ParameterHasNoTypeDeclarationProblem.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/ParameterHasNoTypeDeclarationProblem.java
new file mode 100644
index 0000000..d64d973
--- /dev/null
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/ParameterHasNoTypeDeclarationProblem.java
@@ -0,0 +1,46 @@
+/*
+ *
+ *  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.royale.compiler.problems;
+
+import org.apache.royale.compiler.tree.as.IASNode;
+
+/**
+ * <pre>
+ * Example: 
+ *      function foo(baz) : void {
+ *      }
+ * </pre>
+ *          
+ */
+public final class ParameterHasNoTypeDeclarationProblem extends 
SemanticWarningProblem
+{
+    public static final String DESCRIPTION = "parameter '${paramName}' for 
function '${functionName}' has no type declaration.";
+    
+    public static final int warningCode = 1008;
+    public ParameterHasNoTypeDeclarationProblem(IASNode site, String 
paramName, String functionName)
+    {
+        super(site);
+               this.paramName = paramName;
+               this.functionName = functionName;
+    }
+    
+    public final String paramName;
+    public final String functionName;
+}
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/InterfaceDirectiveProcessor.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/InterfaceDirectiveProcessor.java
index 2177b77..f564c1b 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/InterfaceDirectiveProcessor.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/as/codegen/InterfaceDirectiveProcessor.java
@@ -347,6 +347,8 @@ public class InterfaceDirectiveProcessor extends 
DirectiveProcessor
 
         // Warn if there is no return type
         SemanticUtils.checkReturnValueHasNoTypeDeclaration(interfaceScope, 
func, func_def);
+        // Warn if there are any missing parameter types
+        SemanticUtils.checkParametersHaveNoTypeDeclaration(interfaceScope, 
func, func_def);
 
         // Interface methods can't have a body
         if( func.hasBody() )
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
index d74fae3..dc7868e 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
@@ -942,6 +942,7 @@ public class MethodBodySemanticChecker
     public void checkFunctionDefinition(IFunctionNode iNode, 
FunctionDefinition def )
     {
         SemanticUtils.checkReturnValueHasNoTypeDeclaration(this.currentScope, 
iNode, def);
+        SemanticUtils.checkParametersHaveNoTypeDeclaration(this.currentScope, 
iNode, def);
         
         if (SemanticUtils.isInFunction(iNode))
         {
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
index 344f14f..ecffb8b 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
@@ -104,6 +104,7 @@ import 
org.apache.royale.compiler.problems.DeprecatedAPIWithReplacementProblem;
 import 
org.apache.royale.compiler.problems.DeprecatedAPIWithSinceAndReplacementProblem;
 import org.apache.royale.compiler.problems.DeprecatedAPIWithSinceProblem;
 import org.apache.royale.compiler.problems.ICompilerProblem;
+import 
org.apache.royale.compiler.problems.ParameterHasNoTypeDeclarationProblem;
 import 
org.apache.royale.compiler.problems.ReturnValueHasNoTypeDeclarationProblem;
 import org.apache.royale.compiler.problems.ScopedToDefaultNamespaceProblem;
 import org.apache.royale.compiler.problems.UnknownSuperclassProblem;
@@ -2492,6 +2493,36 @@ public class SemanticUtils
     }
     
     /**
+     * Checks that a given function's parameters have a type, and logs a 
problem if not
+     * 
+     * @param scope is the scope where problems are to be logged
+     * @param node is the function node that is being checked (used for 
location reporting)
+     * @param func is the definition of the function to be checked.
+     */
+    public static void checkParametersHaveNoTypeDeclaration(LexicalScope 
scope, IFunctionNode node, IFunctionDefinition func)
+    {
+        for (IParameterNode paramNode : node.getParameterNodes())
+        {
+            IExpressionNode paramType = paramNode.getVariableTypeNode();
+
+            // check for parameter type declaration
+            if (paramType == null)
+            {
+                scope.addProblem(new 
ParameterHasNoTypeDeclarationProblem(paramNode, paramNode.getName(), 
node.getName()));
+            }
+            else if(paramType.getAbsoluteStart() == -1 && 
paramType.getAbsoluteEnd() == -1
+                    && paramType instanceof ILanguageIdentifierNode)
+            {
+                ILanguageIdentifierNode identifier = (ILanguageIdentifierNode) 
paramType;
+                if 
(identifier.getKind().equals(LanguageIdentifierKind.ANY_TYPE))
+                {
+                    scope.addProblem(new 
ParameterHasNoTypeDeclarationProblem(paramNode, paramNode.getName(), 
node.getName()));
+                }
+            }
+        }
+    }
+    
+    /**
      * Checks that a given function definition has a return type, and logs a 
problem if not
      * 
      * @param scope is the scope where problems are to be logged

Reply via email to