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/11/20 17:37:49 UTC

[royale-compiler] 02/02: MXMLArrayNode: fixed issue where ArrayElementType was enforced for some arrays, but not ones with [DefaultProperty]

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

View the commit online:
https://github.com/apache/royale-compiler/commit/d5b247ec9b5a8a30ed74c35a5b7dd1850f966ec1

commit d5b247ec9b5a8a30ed74c35a5b7dd1850f966ec1
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Nov 20 09:37:39 2019 -0800

    MXMLArrayNode: fixed issue where ArrayElementType was enforced for some arrays, but not ones with [DefaultProperty]
    
    This is a compatibility fix where the Flex SDK compiler enforced it, but the Royale compiler has not been enforcing it.
---
 .../compiler/internal/tree/mxml/MXMLArrayNode.java | 23 ++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLArrayNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLArrayNode.java
index 9d7984f..af2ec7e 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLArrayNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLArrayNode.java
@@ -138,11 +138,11 @@ class MXMLArrayNode extends MXMLInstanceNode implements IMXMLArrayNode
 
         String tagName = builder.getFileScope().resolveTagToQualifiedName(childTag);
         IDefinition definition = project.getScope().findDefinitionByName(tagName);
-        if (definition instanceof ClassDefinition)
+        if (definition instanceof IClassDefinition)
         {
             MXMLInstanceNode instanceNode =
                     MXMLInstanceNode.createInstanceNode(builder, tagName, this);
-            instanceNode.setClassReference(project, (ClassDefinition)definition); // TODO Move this logic to initializeFromTag().
+            instanceNode.setClassReference(project, (IClassDefinition)definition); // TODO Move this logic to initializeFromTag().
             instanceNode.initializeFromTag(builder, childTag);
             info.addChildNode(instanceNode);
 
@@ -150,7 +150,7 @@ class MXMLArrayNode extends MXMLInstanceNode implements IMXMLArrayNode
             // the [ArrayElementType] of the property of type Array that's being set.
             if (arrayElementType != null)
             {
-                if (!((ClassDefinition)definition).isInstanceOf(arrayElementType, project))
+                if (!((IClassDefinition)definition).isInstanceOf(arrayElementType, project))
                 {
                     ICompilerProblem problem = new MXMLIncompatibleArrayElementProblem(
                             childTag, propertyName, arrayElementType, definition.getQualifiedName());
@@ -233,6 +233,9 @@ class MXMLArrayNode extends MXMLInstanceNode implements IMXMLArrayNode
 
         setClassReference(project, IASLanguageConstants.Array);
 
+        propertyName = defaultPropertyDefinition.getBaseName();
+        arrayElementType = defaultPropertyDefinition.getArrayElementType(project);
+
         List<IMXMLNode> children = new ArrayList<IMXMLNode>();
         for (IMXMLUnitData unit : contentUnits)
         {
@@ -258,9 +261,21 @@ class MXMLArrayNode extends MXMLInstanceNode implements IMXMLArrayNode
                     {
                         MXMLInstanceNode childNode = MXMLInstanceNode.createInstanceNode(
                                 builder, definition.getQualifiedName(), this);
-                        childNode.setClassReference(project, (ClassDefinition)definition); // TODO Move this logic to initializeFromTag().
+                        childNode.setClassReference(project, (IClassDefinition)definition); // TODO Move this logic to initializeFromTag().
                         childNode.initializeFromTag(builder, tag);
                         children.add(childNode);
+
+                        // Report problem if actual type of array element is incompatible with
+                        // the [ArrayElementType] of the property of type Array that's being set.
+                        if (arrayElementType != null)
+                        {
+                            if (!((IClassDefinition)definition).isInstanceOf(arrayElementType, project))
+                            {
+                                ICompilerProblem problem = new MXMLIncompatibleArrayElementProblem(
+                                    tag, propertyName, arrayElementType, definition.getQualifiedName());
+                                builder.addProblem(problem);
+                            }
+                        }
                     }
                     else
                     {