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 f2a2a945795f1d2f0c3ebb42173e2fe63ff669d2
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Sep 18 09:05:08 2024 -0700

    implement -compiler.warn-bad-bool-assignment option
    
    Default to false, but allows it to be enabled by other frameworks, like 
Flex SDK
---
 .../clients/problems/ProblemSettingsFilter.java    |  2 +
 .../royale/compiler/config/Configuration.java      |  7 +---
 .../NonBooleanUsedWhereBooleanExpectedProblem.java | 43 ++++++++++++++++++++++
 .../semantics/MethodBodySemanticChecker.java       | 20 +++++++++-
 4 files changed, 66 insertions(+), 6 deletions(-)

diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
index 067062410..4c57a968e 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
@@ -170,6 +170,8 @@ public class ProblemSettingsFilter implements IProblemFilter
                 ICompilerSettings.WARN_NO_TYPE_DECL);
         setShowActionScriptWarning(ThisUsedInClosureProblem.class, 
                 ICompilerSettings.WARN_THIS_WITHIN_CLOSURE);
+        
setShowActionScriptWarning(NonBooleanUsedWhereBooleanExpectedProblem.class, 
+                ICompilerSettings.WARN_BAD_BOOLEAN_ASSIGNMENT);
     }
 
     /**
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
index 0e1a8c83f..206ad4851 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
@@ -3502,7 +3502,7 @@ public class Configuration
     // 'compiler.warn-bad-bool-assignment' option
     //
 
-    private boolean warn_bad_bool_assignment = true;
+    private boolean warn_bad_bool_assignment = false;
 
     public boolean warn_bad_bool_assignment()
     {
@@ -3513,10 +3513,7 @@ public class Configuration
     @Mapping({ "compiler", "warn-bad-bool-assignment" })
     public void setCompilerWarnBadBoolAssignment(ConfigurationValue cv, 
boolean b)
     {
-        // This option is set in royale-config.xml so only warn
-        // if the user sets a non-default value.
-        if (b != warn_bad_bool_assignment)
-            addRemovedConfigurationOptionProblem(cv);
+        warn_bad_bool_assignment = b;
     }
 
     //
diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/problems/NonBooleanUsedWhereBooleanExpectedProblem.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/NonBooleanUsedWhereBooleanExpectedProblem.java
new file mode 100644
index 000000000..988250ba1
--- /dev/null
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/problems/NonBooleanUsedWhereBooleanExpectedProblem.java
@@ -0,0 +1,43 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.royale.compiler.problems;
+
+import org.apache.royale.compiler.tree.as.IASNode;
+
+/**
+ *  NonBooleanUsedWhereBooleanExpectedProblem is emitted when
+ *  the MethodBodySemanticChecker detects an assignment to Boolean with a
+ *  type that is not Boolean.
+ */
+public final class NonBooleanUsedWhereBooleanExpectedProblem extends 
SemanticWarningProblem
+{
+    public static String DESCRIPTION =
+        "${className} used where a Boolean value was expected.  The expression 
will be type coerced to Boolean.";
+    
+    public static final int errorCode = 3590;
+ 
+    public NonBooleanUsedWhereBooleanExpectedProblem(IASNode site, String 
className)
+    {
+        super(site);
+        this.className = className;
+    }
+    
+    public final String className;
+}
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 17557a239..1f1372a32 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
@@ -532,7 +532,7 @@ public class MethodBodySemanticChecker
         if (rightNode instanceof IExpressionNode)
         {
             IDefinition rightType = 
((IExpressionNode)rightNode).resolveType(project);
-            final boolean leftIsNumericOrBoolean = 
SemanticUtils.isNumericTypeOrBoolean(leftType, project);   
+            final boolean leftIsNumericOrBoolean = 
SemanticUtils.isNumericTypeOrBoolean(leftType, project);  
             final boolean rightIsNull =  SemanticUtils.isBuiltin(rightType, 
BuiltinType.NULL, project);
             
             if (leftIsNumericOrBoolean && rightIsNull)
@@ -542,6 +542,15 @@ public class MethodBodySemanticChecker
                         new 
IncompatibleDefaultValueOfTypeNullProblem(rightNode, leftType.getBaseName()) :
                         new NullUsedWhereOtherExpectedProblem(rightNode, 
leftType.getBaseName()));
             }
+             
+            final boolean leftIsBoolean = SemanticUtils.isBuiltin(leftType, 
BuiltinType.BOOLEAN, project);
+            final boolean rightIsBoolean = SemanticUtils.isBuiltin(rightType, 
BuiltinType.BOOLEAN, project);
+            
+            if (leftIsBoolean && !rightIsBoolean)
+            {
+                String rightTypeName = rightType != null ? 
rightType.getBaseName() : "Non-Boolean value";
+                addProblem(new 
NonBooleanUsedWhereBooleanExpectedProblem(rightNode, rightTypeName));
+            }
         }
     }
     
@@ -2634,6 +2643,15 @@ public class MethodBodySemanticChecker
                 {
                     addProblem(new 
NullUsedWhereOtherExpectedProblem(returnExpression, return_type.getBaseName()));
                 }
+             
+                final boolean leftIsBoolean = 
SemanticUtils.isBuiltin(return_type, BuiltinType.BOOLEAN, project);
+                final boolean rightIsBoolean = 
SemanticUtils.isBuiltin(rightType, BuiltinType.BOOLEAN, project);
+                
+                if (leftIsBoolean && !rightIsBoolean)
+                {
+                    String rightTypeName = rightType != null ? 
rightType.getBaseName() : "Non-Boolean value";
+                    addProblem(new 
NonBooleanUsedWhereBooleanExpectedProblem(returnExpression, rightTypeName));
+                }
             }
             catch ( Exception namerezo_problem )
             {

Reply via email to