You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2019/06/11 22:07:58 UTC

[royale-compiler] branch develop updated: added missing error for type parameters on non-Vector types

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 0d9cad9  added missing error for type parameters on non-Vector types
0d9cad9 is described below

commit 0d9cad99f35d1afe88d056d7a59aa24ab1b35b85
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Jun 11 15:07:50 2019 -0700

    added missing error for type parameters on non-Vector types
    
    Until now, types like Array.<String> and Boolean.<Object> would not result in an error
---
 .../semantics/MethodBodySemanticChecker.java       | 17 ++++++++++
 ...eParametersWithNonParameterizedTypeProblem.java | 38 ++++++++++++++++++++++
 2 files changed, 55 insertions(+)

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 067c2fe..f8fb122 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
@@ -87,6 +87,7 @@ import org.apache.royale.compiler.tree.as.INumericLiteralNode;
 import org.apache.royale.compiler.tree.as.IParameterNode;
 import org.apache.royale.compiler.tree.as.IReturnNode;
 import org.apache.royale.compiler.tree.as.IScopedNode;
+import org.apache.royale.compiler.tree.as.ITypedExpressionNode;
 import org.apache.royale.compiler.tree.as.IUnaryOperatorNode;
 import org.apache.royale.compiler.tree.as.IVariableNode;
 import org.apache.royale.compiler.internal.as.codegen.ABCGeneratingReducer;
@@ -2565,6 +2566,22 @@ public class MethodBodySemanticChecker
             }
         }
 
+        ExpressionNodeBase typeNode = var.getTypeNode();
+        IExpressionNode currentTypeNode = typeNode;
+        while (currentTypeNode instanceof ITypedExpressionNode)
+        {
+            ITypedExpressionNode typedNode = (ITypedExpressionNode) currentTypeNode;
+            IExpressionNode collectionNode = typedNode.getCollectionNode();
+            IDefinition collectionType = collectionNode.resolve(project);
+            if (collectionType != null
+                    && !collectionType.getQualifiedName().equals(IASLanguageConstants.Vector_qname))
+            {
+                currentScope.addProblem(new TypeParametersWithNonParameterizedTypeProblem(collectionNode));
+            }
+            //keep checking while there are nested types
+            currentTypeNode = typedNode.getTypeNode();
+        }
+
         // check if thise is an assignment in this declaration.
         // If so, do checks on that
         final ExpressionNodeBase rightNode = var.getAssignedValueNode();
diff --git a/compiler/src/main/java/org/apache/royale/compiler/problems/TypeParametersWithNonParameterizedTypeProblem.java b/compiler/src/main/java/org/apache/royale/compiler/problems/TypeParametersWithNonParameterizedTypeProblem.java
new file mode 100644
index 0000000..8287171
--- /dev/null
+++ b/compiler/src/main/java/org/apache/royale/compiler/problems/TypeParametersWithNonParameterizedTypeProblem.java
@@ -0,0 +1,38 @@
+/*
+ *
+ *  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;
+
+/**
+ *  Semantics diagnostic emitted when the method body
+ *  semantic checker detects an attempt to add type parameters to a
+ *  non-parameterized type.
+ */
+public final class TypeParametersWithNonParameterizedTypeProblem extends SemanticProblem
+{
+    public static final String DESCRIPTION =
+        "Type parameters with a non-parameterized type.";
+
+    public TypeParametersWithNonParameterizedTypeProblem(IASNode site)
+    {
+        super(site);
+    }
+}