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 a6290f7a2 MethodBodySemanticChecker: certain expressions that can 
resolve to a function type expression can be nested, so those need to be 
checked too
a6290f7a2 is described below

commit a6290f7a23c97b04d8229dfee6877b0d3c3802cc
Author: Josh Tynjala <[email protected]>
AuthorDate: Tue Feb 17 14:53:31 2026 -0800

    MethodBodySemanticChecker: certain expressions that can resolve to a 
function type expression can be nested, so those need to be checked too
---
 .../semantics/MethodBodySemanticChecker.java       | 187 ++++++++++++---------
 1 file changed, 111 insertions(+), 76 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 e767901de..853e323bd 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
@@ -310,84 +310,9 @@ public class MethodBodySemanticChecker
                 return;
             }
         }
-        IFunctionTypeExpressionNode actualFuncTypeExpr = null;
 
         IExpressionNode rightExpression = (IExpressionNode) rightNode;
-        if (rightExpression instanceof IFunctionCallNode
-            && !(rightExpression instanceof IArrowFunctionBindNode))
-        {
-            IFunctionCallNode funcCallNode = (IFunctionCallNode) 
rightExpression;
-            actualFuncTypeExpr = 
resolveReturnedFunctionTypeExpressionFromCall(funcCallNode);
-        }
-
-        if (actualFuncTypeExpr == null)
-        {
-            ITypeDefinition resolvedRightType = 
rightExpression.resolveType(project);
-            if 
(!project.getBuiltinType(BuiltinType.FUNCTION).equals(resolvedRightType))
-            {
-                // problems for assigning a non-function type are handled 
elsewhere
-                return;
-            }
-
-            IDefinition resolvedRightDef = null;
-            if (rightExpression instanceof BinaryOperatorLogicalAndNode
-                    || rightExpression instanceof BinaryOperatorLogicalOrNode)
-            {
-                IBinaryOperatorNode binaryNode = (IBinaryOperatorNode) 
rightExpression;
-                IExpressionNode leftOperand = binaryNode.getLeftOperandNode();
-                IExpressionNode rightOperand = 
binaryNode.getRightOperandNode();
-                IDefinition resolvedLeftOperandDef = 
leftOperand.resolve(project);
-                IDefinition resolvedRightOperandDef = 
rightOperand.resolve(project);
-                if (resolvedLeftOperandDef != null && resolvedRightOperandDef 
!= null)
-                {
-                    IFunctionTypeExpressionNode leftFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedLeftOperandDef, 
leftOperand, project, this.currentScope.getProblems());
-                    IFunctionTypeExpressionNode rightFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedRightOperandDef, 
rightOperand, project, this.currentScope.getProblems());
-                    if (leftFuncTypeExpr != null && rightFuncTypeExpr != null)
-                    {
-                        if 
(leftFuncTypeExpr.resolveSignature(project).equals(rightFuncTypeExpr.resolveSignature(project)))
-                        {
-                            actualFuncTypeExpr = leftFuncTypeExpr;
-                        }
-                    }
-                }
-            }
-            else if (rightExpression instanceof ITernaryOperatorNode)
-            {
-                ITernaryOperatorNode ternaryNode = (ITernaryOperatorNode) 
rightExpression;
-                IExpressionNode leftOperand = ternaryNode.getLeftOperandNode();
-                IExpressionNode rightOperand = 
ternaryNode.getRightOperandNode();
-                IDefinition resolvedLeftOperandDef = 
leftOperand.resolve(project);
-                IDefinition resolvedRightOperandDef = 
rightOperand.resolve(project);
-                if (resolvedLeftOperandDef != null && resolvedRightOperandDef 
!= null)
-                {
-                    IFunctionTypeExpressionNode leftFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedLeftOperandDef, 
leftOperand, project, this.currentScope.getProblems());
-                    IFunctionTypeExpressionNode rightFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedRightOperandDef, 
rightOperand, project, this.currentScope.getProblems());
-                    if (leftFuncTypeExpr != null && rightFuncTypeExpr != null)
-                    {
-                        if 
(leftFuncTypeExpr.resolveSignature(project).equals(rightFuncTypeExpr.resolveSignature(project)))
-                        {
-                            actualFuncTypeExpr = leftFuncTypeExpr;
-                        }
-                    }
-                }
-            }
-            else if (rightExpression instanceof IArrowFunctionBindNode)
-            {
-                IArrowFunctionBindNode arrowBindNode = 
(IArrowFunctionBindNode) rightExpression;
-                IFunctionObjectNode arrowFuncObjNode = 
arrowBindNode.getFunctionObjectNode();
-                IFunctionNode arrowFuncNode = 
arrowFuncObjNode.getFunctionNode();
-                resolvedRightDef = arrowFuncNode.getDefinition();
-            }
-            else
-            {
-                resolvedRightDef = rightExpression.resolve(project);
-            }
-
-            if (resolvedRightDef != null)
-            {
-                actualFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedRightDef, 
rightExpression, project, this.currentScope.getProblems());
-            }
-        }
+        IFunctionTypeExpressionNode actualFuncTypeExpr = 
resolveFunctionTypeExpressionFromExpression(rightExpression);
         
         checkFunctionSignatureAssignment(expectedFuncTypeExpr, 
actualFuncTypeExpr, rightExpression);
     }
@@ -533,6 +458,116 @@ public class MethodBodySemanticChecker
             addProblem(new ImplicitCoercionToUnrelatedTypeProblem(actualSite, 
actualFuncTypeExpr.resolveSignature(project), 
expectedFuncTypeExpr.resolveSignature(project)));
         }
     }
+
+    private IFunctionTypeExpressionNode 
resolveFunctionTypeExpressionFromExpression(IExpressionNode expressionNode)
+    {
+        if (expressionNode instanceof IFunctionCallNode
+            && !(expressionNode instanceof IArrowFunctionBindNode))
+        {
+            IFunctionCallNode funcCallNode = (IFunctionCallNode) 
expressionNode;
+            IFunctionTypeExpressionNode returnedFuncTypeExpr = 
resolveReturnedFunctionTypeExpressionFromCall(funcCallNode);
+            if (returnedFuncTypeExpr != null)
+            {
+                return returnedFuncTypeExpr;
+            }
+        }
+        else if (expressionNode instanceof BinaryOperatorLogicalAndNode
+                || expressionNode instanceof BinaryOperatorLogicalOrNode)
+        {
+            IBinaryOperatorNode binaryNode = (IBinaryOperatorNode) 
expressionNode;
+
+            IExpressionNode leftOperand = binaryNode.getLeftOperandNode();
+            IFunctionTypeExpressionNode leftFuncTypeExpr = 
resolveFunctionTypeExpressionFromExpression(leftOperand);
+            if (leftFuncTypeExpr == null)
+            {
+                IDefinition resolvedLeftOperandDef = 
leftOperand.resolve(project);
+                if (resolvedLeftOperandDef != null)
+                {
+                    leftFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedLeftOperandDef, 
leftOperand, project, this.currentScope.getProblems());
+                }
+            }
+                    
+            IExpressionNode rightOperand = binaryNode.getRightOperandNode();
+            IFunctionTypeExpressionNode rightFuncTypeExpr = 
resolveFunctionTypeExpressionFromExpression(rightOperand);
+            if (rightFuncTypeExpr == null)
+            {
+                IDefinition resolvedRightOperandDef = 
rightOperand.resolve(project);
+                if (resolvedRightOperandDef != null)
+                {
+                    rightFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedRightOperandDef, 
rightOperand, project, this.currentScope.getProblems());
+                }
+            }
+
+            if (leftFuncTypeExpr != null && rightFuncTypeExpr != null)
+            {
+                if 
(leftFuncTypeExpr.resolveSignature(project).equals(rightFuncTypeExpr.resolveSignature(project)))
+                {
+                    return leftFuncTypeExpr;
+                }
+            }
+        }
+        else if (expressionNode instanceof ITernaryOperatorNode)
+        {
+            ITernaryOperatorNode ternaryNode = (ITernaryOperatorNode) 
expressionNode;
+
+            IExpressionNode leftOperand = ternaryNode.getLeftOperandNode();
+            IFunctionTypeExpressionNode leftFuncTypeExpr = 
resolveFunctionTypeExpressionFromExpression(leftOperand);
+            if (leftFuncTypeExpr == null)
+            {
+                IDefinition resolvedLeftOperandDef = 
leftOperand.resolve(project);
+                if (resolvedLeftOperandDef != null)
+                {
+                    leftFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedLeftOperandDef, 
leftOperand, project, this.currentScope.getProblems());
+                }
+            }
+                    
+            IExpressionNode rightOperand = ternaryNode.getRightOperandNode();
+            IFunctionTypeExpressionNode rightFuncTypeExpr = 
resolveFunctionTypeExpressionFromExpression(rightOperand);
+            if (rightFuncTypeExpr == null)
+            {
+                IDefinition resolvedRightOperandDef = 
rightOperand.resolve(project);
+                if (resolvedRightOperandDef != null)
+                {
+                    rightFuncTypeExpr = 
FunctionTypeExpressionNode.createFromDefinition(resolvedRightOperandDef, 
rightOperand, project, this.currentScope.getProblems());
+                }
+            }
+
+            if (leftFuncTypeExpr != null && rightFuncTypeExpr != null)
+            {
+                if 
(leftFuncTypeExpr.resolveSignature(project).equals(rightFuncTypeExpr.resolveSignature(project)))
+                {
+                    return leftFuncTypeExpr;
+                }
+            }
+        }
+
+        ITypeDefinition resolvedExprType = expressionNode.resolveType(project);
+        if 
(!project.getBuiltinType(BuiltinType.FUNCTION).equals(resolvedExprType))
+        {
+            // problems for assigning a non-function type are handled elsewhere
+            return null;
+        }
+
+        IDefinition resolvedRightDef = null;
+        if (expressionNode instanceof IArrowFunctionBindNode)
+        {
+            IArrowFunctionBindNode arrowBindNode = (IArrowFunctionBindNode) 
expressionNode;
+            IFunctionObjectNode arrowFuncObjNode = 
arrowBindNode.getFunctionObjectNode();
+            IFunctionNode arrowFuncNode = arrowFuncObjNode.getFunctionNode();
+            resolvedRightDef = arrowFuncNode.getDefinition();
+        }
+        else
+        {
+            resolvedRightDef = expressionNode.resolve(project);
+        }
+
+        if (resolvedRightDef != null)
+        {
+            return 
FunctionTypeExpressionNode.createFromDefinition(resolvedRightDef, 
expressionNode, project, this.currentScope.getProblems());
+        }
+
+        return null;
+    }
     
     /**
      * Checks that the value (RHS) is appropriate, given the type of the LHS

Reply via email to