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 <[email protected]>
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()
     {

Reply via email to