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/01/23 17:30:14 UTC
[royale-compiler] branch develop updated:
MethodBodySemanticChecker: allows a local variable to be instantiated only
if it's of one of these types: Class, Function, Object, and *.
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 9971b52 MethodBodySemanticChecker: allows a local variable to be instantiated only if it's of one of these types: Class, Function, Object, and *.
9971b52 is described below
commit 9971b522c69a61b05ec61e3d67946c98af27b161
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Jan 23 09:30:09 2019 -0800
MethodBodySemanticChecker: allows a local variable to be instantiated only if it's of one of these types: Class, Function, Object, and *.
var abc:Class;
new abc(); //allowed
var xyz:String;
new xyz(); //problem
This matches the behavior in the Flex SDK compiler.
---
.../semantics/MethodBodySemanticChecker.java | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
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 a0b6785..0e009fe 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
@@ -2049,7 +2049,25 @@ public class MethodBodySemanticChecker
if ( class_binding.isLocal() )
{
- // No checking required.
+ // Note: previously, local bindings were not checked at all, but
+ // actually, variables of most types cannot be used with a "new"
+ // expression -JT
+
+ if (def instanceof IVariableDefinition)
+ {
+ ITypeDefinition typeDef = def.resolveType(project);
+ if (typeDef != null
+ && !SemanticUtils.isBuiltin(typeDef, BuiltinType.CLASS, project)
+ && !SemanticUtils.isBuiltin(typeDef, BuiltinType.FUNCTION, project)
+ && !SemanticUtils.isBuiltin(typeDef, BuiltinType.OBJECT, project)
+ && !SemanticUtils.isBuiltin(typeDef, BuiltinType.ANY_TYPE, project))
+ {
+ addProblem(new CallUndefinedMethodProblem(
+ roundUpUsualSuspects(class_binding, iNode),
+ class_binding.getName().getBaseName()
+ ));
+ }
+ }
}
else if ( def == null && utils.definitionCanBeAnalyzed(class_binding) && !(class_binding.getName().isTypeName()) )
{