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 2020/08/18 20:16:50 UTC
[royale-compiler] branch develop updated: compiler: allow classes
with private constructors to be used for function-style casts
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 9c4338a compiler: allow classes with private constructors to be used for function-style casts
9c4338a is described below
commit 9c4338ab3ef43a04d75182f3289ae83cb4aea971
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Aug 18 13:16:43 2020 -0700
compiler: allow classes with private constructors to be used for function-style casts
Was able to revert the changes in #158 because this fix also makes that change unnecessary.
---
.../compiler/internal/definitions/ClassDefinition.java | 2 +-
.../internal/definitions/FunctionDefinition.java | 13 +++++++++++++
.../royale/compiler/internal/scopes/ASScopeCache.java | 16 ----------------
.../royale/compiler/internal/tree/as/FunctionNode.java | 10 +---------
4 files changed, 15 insertions(+), 26 deletions(-)
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/ClassDefinition.java b/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/ClassDefinition.java
index 0454ef2..1b07a55 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/ClassDefinition.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/ClassDefinition.java
@@ -315,7 +315,7 @@ public class ClassDefinition extends ClassDefinitionBase implements IClassDefini
this.constructor = constructor;
if(this.constructor.isPrivate()
- && this.constructor.getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_PRIVATE_CONSTRUCTOR) == null)
+ && getMetaTagByName(IMetaAttributeConstants.ATTRIBUTE_PRIVATE_CONSTRUCTOR) == null)
{
// ensures that the constructor remains private when compiled into
// a library because the metadata is how private constructors are
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/FunctionDefinition.java b/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/FunctionDefinition.java
index 51f7366..562b4d6 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/FunctionDefinition.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/FunctionDefinition.java
@@ -29,6 +29,7 @@ import java.util.List;
import org.apache.royale.compiler.common.DependencyType;
import org.apache.royale.compiler.constants.IASKeywordConstants;
import org.apache.royale.compiler.constants.IMetaAttributeConstants;
+import org.apache.royale.compiler.constants.INamespaceConstants;
import org.apache.royale.compiler.definitions.*;
import org.apache.royale.compiler.definitions.references.INamespaceReference;
import org.apache.royale.compiler.definitions.metadata.IMetaTag;
@@ -295,6 +296,18 @@ public class FunctionDefinition extends ScopedDefinitionBase implements IFunctio
}
if (isConstructor())
{
+ IFunctionNode funcNode = getFunctionNode();
+ if (funcNode != null
+ && INamespaceConstants.private_.equals(funcNode.getNamespace()))
+ {
+ // super.isPrivate() checks the namespace reference, but all
+ // constructors always use this namespace reference:
+ // NamespaceDefinition.getCodeModelImplicitDefinitionNamespace()
+ // constructors can't use the normal private reference or
+ // they'll incorrectly show up in scope searches.
+ return true;
+ }
+
IDefinition parent = getParent();
if (parent == null)
{
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/scopes/ASScopeCache.java b/compiler/src/main/java/org/apache/royale/compiler/internal/scopes/ASScopeCache.java
index a2c463e..5961c46 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/scopes/ASScopeCache.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/scopes/ASScopeCache.java
@@ -155,14 +155,6 @@ public class ASScopeCache
if (to != null)
project.addDependency(from, to, dt, qname);
}
- if (favorTypes
- && result instanceof IFunctionDefinition
- && ((IFunctionDefinition) result).isConstructor())
- {
- // if it's a constructor, but we prefer a type, switch to the type
- // this is necessary for private constructors
- result = result.getParent();
- }
return result;
}
@@ -222,14 +214,6 @@ public class ASScopeCache
result = def;
}
}
- if (favorTypes
- && result instanceof IFunctionDefinition
- && ((IFunctionDefinition) result).isConstructor())
- {
- // if it's a constructor, but we prefer a type, switch to the type
- // this is necessary for private constructors
- result = result.getParent();
- }
return result;
}
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
index 8fc51e3..1a5bf10 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
@@ -675,16 +675,8 @@ public class FunctionNode extends BaseTypedDefinitionNode implements IFunctionNo
classNode.constructorNode = this;
}
}
- // if the namespace reference is private, don't change it
- if(!(funcDef.getNamespaceReference() instanceof INamespaceDefinition.IPrivateNamespaceDefinition))
- {
- funcDef.setNamespaceReference(NamespaceDefinition.getCodeModelImplicitDefinitionNamespace());
- }
- }
- else
- {
- funcDef.setNamespaceReference(NamespaceDefinition.getCodeModelImplicitDefinitionNamespace());
}
+ funcDef.setNamespaceReference(NamespaceDefinition.getCodeModelImplicitDefinitionNamespace());
}
}