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 2026/01/26 21:16:34 UTC

(royale-compiler) branch develop updated (a6c8e5927 -> 2404c68ea)

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


    from a6c8e5927 FunctionCallEmitter: fix Vector.<Foo>() global function when using custom vector emulation class
     new 5ed20c963 FunctionTypeExpressionNode: fix null AST node when parsing signature
     new 2404c68ea MethodBodySemanticChecker: another exception for return types that aren't the same or subclasses (any (*) type)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../semantics/MethodBodySemanticChecker.java       |  9 ++++-
 .../tree/as/FunctionTypeExpressionNode.java        | 46 ++++++++++++++++++----
 .../test/java/as/ASStrictFunctionTypesTests.java   | 27 +++++++++++++
 3 files changed, 73 insertions(+), 9 deletions(-)


(royale-compiler) 01/02: FunctionTypeExpressionNode: fix null AST node when parsing signature

Posted by jo...@apache.org.
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

commit 5ed20c96320eee806802895c6c12219553cc4a64
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Jan 26 12:13:23 2026 -0800

    FunctionTypeExpressionNode: fix null AST node when parsing signature
    
    Falls back to getting the source locations from the definition instead (which is necessary when compiled into a SWC, since the AST nodes won't exist anymore)
---
 .../tree/as/FunctionTypeExpressionNode.java        | 46 ++++++++++++++++++----
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionTypeExpressionNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionTypeExpressionNode.java
index 9e2e0f221..e9c76b4bc 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionTypeExpressionNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionTypeExpressionNode.java
@@ -48,6 +48,7 @@ import org.apache.royale.compiler.problems.UnexpectedExceptionProblem;
 import org.apache.royale.compiler.projects.ICompilerProject;
 import org.apache.royale.compiler.tree.ASTNodeID;
 import org.apache.royale.compiler.tree.as.IASNode;
+import org.apache.royale.compiler.tree.as.IDefinitionNode;
 import org.apache.royale.compiler.tree.as.IContainerNode.ContainerType;
 import org.apache.royale.compiler.tree.as.IExpressionNode;
 import org.apache.royale.compiler.tree.as.IFunctionTypeExpressionNode;
@@ -123,7 +124,7 @@ public class FunctionTypeExpressionNode extends ExpressionNodeBase implements IF
         }
 
         ASScope asScope = (ASScope) definition.getContainingScope();
-        return FunctionTypeExpressionNode.parseSignature(signature, asScope, location, project, problems);
+        return FunctionTypeExpressionNode.parseSignature(signature, asScope, definition, project, problems);
     }
 
     public static FunctionTypeExpressionNode createFromFunctionDefinition(IFunctionDefinition functionDefinition, ICompilerProject project)
@@ -183,7 +184,38 @@ public class FunctionTypeExpressionNode extends ExpressionNodeBase implements IF
         return funcTypeExprNode;
     }
 
-    private static FunctionTypeExpressionNode parseSignature(String signature, ASScope scope, ISourceLocation site, ICompilerProject project, Collection<ICompilerProblem> problems)
+    private static FunctionTypeExpressionNode parseSignature(String signature, ASScope scope, IDefinition sourceDefinition, ICompilerProject project, Collection<ICompilerProblem> problems)
+    {
+        // prefer the actual AST node, if available
+        IDefinitionNode sourceNode = sourceDefinition.getNode();
+        if (sourceNode != null)
+        {
+            return parseSignature(signature, scope, sourceNode, project, problems);
+        }
+        String sourcePath = sourceDefinition.getSourcePath();
+        int start = sourceDefinition.getAbsoluteStart();
+        int line = sourceDefinition.getLine();
+        int column = sourceDefinition.getColumn();
+        return parseSignature(signature, scope, sourcePath, start, line, column, project, problems);
+    }
+
+    private static FunctionTypeExpressionNode parseSignature(String signature, ASScope scope, ISourceLocation location, ICompilerProject project, Collection<ICompilerProblem> problems)
+    {
+        String sourcePath = null;
+        int start = -1;
+        int line = -1;
+        int column = -1;
+        if (location != null)
+        {
+            sourcePath = location.getSourcePath();
+            start = location.getAbsoluteStart();
+            line = location.getLine();
+            column = location.getColumn();
+        }
+        return parseSignature(signature, scope, sourcePath, start, line, column, project, problems);
+    }
+
+    private static FunctionTypeExpressionNode parseSignature(String signature, ASScope scope, String sourcePath, int start, int line, int column, ICompilerProject project, Collection<ICompilerProblem> problems)
     {
         FunctionTypeExpressionNode funcTypeExpr = null;
         StreamingASTokenizer tokenizer = null;
@@ -192,15 +224,15 @@ public class FunctionTypeExpressionNode extends ExpressionNodeBase implements IF
         {
             tokenizer = StreamingASTokenizer.createForRepairingASTokenizer(
                     new StringReader(signature),
-                    site.getSourcePath(),
+                    sourcePath,
                     null);
-            tokenizer.setSourcePositionAdjustment(site.getAbsoluteStart(), site.getLine(), site.getColumn());
+            tokenizer.setSourcePositionAdjustment(start, line, column);
 
             buffer = new StreamingTokenBuffer(tokenizer);
             buffer.setEnableSemicolonInsertion(false);
 
             final ASParser parser = new ASParser(project.getWorkspace(), buffer);
-            parser.setFilename(site.getSourcePath());
+            parser.setFilename(sourcePath);
             parser.setAllowEmbeds(false);
             IExpressionNode typeNode = parser.type();
             if (typeNode instanceof IFunctionTypeExpressionNode)
@@ -243,7 +275,7 @@ public class FunctionTypeExpressionNode extends ExpressionNodeBase implements IF
         String signature = getSignatureFromDefinition(funcDef, paramDef.getBaseName());
         if (signature != null)
         {
-            return FunctionTypeExpressionNode.parseSignature(signature, scope, paramDef.getNode(), project, project.getProblems());
+            return FunctionTypeExpressionNode.parseSignature(signature, scope, paramDef, project, project.getProblems());
         }
 
         ITypeDefinition paramType = paramDef.resolveType(project);
@@ -264,7 +296,7 @@ public class FunctionTypeExpressionNode extends ExpressionNodeBase implements IF
         String signature = getSignatureFromDefinition(funcDef);
         if (signature != null)
         {
-            return FunctionTypeExpressionNode.parseSignature(signature, scope, funcDef.getNode(), project, project.getProblems());
+            return FunctionTypeExpressionNode.parseSignature(signature, scope, funcDef, project, project.getProblems());
         }
 
         ITypeDefinition returnType = funcDef.resolveReturnType(project);


(royale-compiler) 02/02: MethodBodySemanticChecker: another exception for return types that aren't the same or subclasses (any (*) type)

Posted by jo...@apache.org.
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

commit 2404c68eae3734d9f568faa09e40b6bf56ca474e
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Jan 26 12:28:24 2026 -0800

    MethodBodySemanticChecker: another exception for return types that aren't the same or subclasses (any (*) type)
    
    AS3 allows calling a function with return type void and assigning it to a variable of type any (*). The assigned value will be undefined. Same idea here.
---
 .../semantics/MethodBodySemanticChecker.java       |  9 ++++++--
 .../test/java/as/ASStrictFunctionTypesTests.java   | 27 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

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 6762d9494..642d4a7d9 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
@@ -470,11 +470,16 @@ public class MethodBodySemanticChecker
             {
                 ITypeDefinition expectedReturnType = (ITypeDefinition) expectedReturnTypeNode.resolve(project);
                 ITypeDefinition actualReturnType = (ITypeDefinition) actualReturnTypeNode.resolve(project);
-                // actual return type must be the same or a subclass
-                // but if expected is void, any return type is accepted because it will be ignored anyway
+                // actual return type must be the same or a subclass, with a
+                // couple of exceptions:
+                // 1. if expected is void, all return types are accepted because
+                //    the value will be ignored anyway
+                // 2. if expect is any, all return types are accepted, including
+                //    void (which is considered to be returning undefined)
                 if (expectedReturnType != null
                         && actualReturnType != null
                         && !expectedReturnType.equals(project.getBuiltinType(BuiltinType.VOID))
+                        && !expectedReturnType.equals(project.getBuiltinType(BuiltinType.ANY_TYPE))
                         && !actualReturnType.isInstanceOf(expectedReturnType, project))
                 {
                     isInvalidSignature = true;
diff --git a/compiler/src/test/java/as/ASStrictFunctionTypesTests.java b/compiler/src/test/java/as/ASStrictFunctionTypesTests.java
index e2c167bd8..1be40d3ba 100644
--- a/compiler/src/test/java/as/ASStrictFunctionTypesTests.java
+++ b/compiler/src/test/java/as/ASStrictFunctionTypesTests.java
@@ -1123,6 +1123,33 @@ public class ASStrictFunctionTypesTests extends ASFeatureTestsBase
         compileAndExpectNoErrors(source, false, false, false, options);
     }
 
+    @Test
+    public void testAssignToReturnAny_assignVariableToVariable()
+    {
+        String[] imports = new String[]
+        {
+        };
+        String[] declarations = new String[]
+        {
+        };
+        String[] testCode = new String[]
+        {
+        };
+        String[] extra = new String[]
+        {
+            "var a:()=>*;",
+            "var b:()=>String;",
+            "a = b;"
+        };
+        String source = getAS(imports, declarations, testCode, extra);
+
+        String[] options = new String[]
+        {
+            "-allow-strict-function-types=true"
+        };
+        compileAndExpectNoErrors(source, false, false, false, options);
+    }
+
     @Test
     public void testAssignStrictTypeToRegular_assignVariableToVariable()
     {