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 4934fcc68bf617f3806ac8d7c8e4335c9ca94eb1 Author: Josh Tynjala <[email protected]> AuthorDate: Tue Jun 20 13:08:35 2023 -0700 BinaryOperatorNodeBase: resolving type of && and || logical operators now accounts for the common base type, using the same algorithm as type inference --- .../compiler/internal/tree/as/BinaryOperatorNodeBase.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java index 03dae65b0..7eda332f8 100644 --- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java +++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java @@ -25,6 +25,7 @@ import antlr.Token; import org.apache.royale.compiler.constants.IASLanguageConstants.BuiltinType; import org.apache.royale.compiler.definitions.ITypeDefinition; +import org.apache.royale.compiler.internal.semantics.SemanticUtils; import org.apache.royale.compiler.parsing.IASToken; import org.apache.royale.compiler.projects.ICompilerProject; import org.apache.royale.compiler.tree.as.IASNode; @@ -384,12 +385,18 @@ public abstract class BinaryOperatorNodeBase extends OperatorNodeBase implements protected ITypeDefinition resolveLogicalType(ICompilerProject project) { // The old compiler says the type of && or || is one of the operand types, - // but only checks if the types are equivalent. - // TODO: Could probably be smarter - calculate common base class and use that as the type? + // but only checks if the types are identical. + // this compiler is smarter and tries to find a common base type, if + // the types are not identical. ITypeDefinition leftType = getLeftOperandNode().resolveType(project); ITypeDefinition rightType = getRightOperandNode().resolveType(project); if (leftType != null && leftType.equals(rightType)) return leftType; + ITypeDefinition commonType = SemanticUtils.resolveCommonType(leftType, rightType, project); + if (commonType != null) + { + return commonType; + } return project.getBuiltinType(BuiltinType.ANY_TYPE); }
