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.
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 @@
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 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 @@
}
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 @@
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 @@
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 @@
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());
}
}