Bug #4483
Unable to use logical variable check in underline statement
100%
History
#2 Updated by Roger Borrello over 6 years ago
Testcase¶
20191231 Update: Fixed in 4207a-11357
Below is the testcase uast/underline_logic_uses_when.p:
def var v1 as character. def var v2 as integer. def var l1 as logical initial false. form v1 v2 with frame f1. /* This yields logical cannot be converted to boolean */ underline v1 when l1 = true v2 when l1 = false with frame f1. assign v1 = if l1 then "" else "Hello". /* This yields "error: not a statement" underline v1 when wip-postcode-opt = true with frame f1. assign v1 = if l1 then "" else "Hello". */ message "Done.".
It generates this error:
[javac] testcases/uast/uast/buildarea/src/com/goldencode/testcases/abl/UnderlineLogic.java:36: error: incompatible types: logical cannot be converted to boolean
[javac] isEqual(l1, true) ? f1Frame.widgetV1() : null,
[javac] ^
[javac] /home/rfb/projects/VirtualBox-VMs/shared/projects/testcases/uast/uast/buildarea/src/com/goldencode/testcases/abl/UnderlineLogic.java:37: error: incompatible types: logical cannot be converted to boolean
[javac] isEqual(l1, false) ? f1Frame.widgetV2() : null
[javac] ^
#3 Updated by Roger Borrello over 6 years ago
Roger Borrello wrote:
Testcase¶
Below is the testcase
uast/underline_logic_uses_when.p:[...]
It generates this error:
[...]
It looks to me like rules/convert/operators.rules has the logic for deciding whether to use isEqual or _isEqual. But it only checks for that if getNoteBoolean("unknown_override") is true (I only see my NOT printfln):
<!-- EQUALS -->
<rule>type == prog.equals
<rule>getNoteBoolean("unknown_override")
<action>printfln("operators.walk_rules: unknown_override %s", this.dumpTree())</action>
<action on="false">printfln("operators.walk_rules: NOT unknown_override %s", this.dumpTree())</action>
<!-- simpler unknown value path -->
<rule>noUnwrap
<action>jtext = "_isUnknown"</action>
<action on="false">jtext = "isUnknown"</action>
</rule>
<rule>javaMethodNames.contains(jtext)
<action>jtext = sprintf("CompareOps.%s", jtext)</action>
</rule>
<!-- normal path -->
<rule on="false">noUnwrap
<action>jtext = "_isEqual"</action>
<action on="false">jtext = "isEqual"</action>
</rule>
</rule>
<action>compimp = true</action>
</rule>
Am I in the right ballpark? Should I more focus on the WHEN?
#4 Updated by Constantin Asofiei over 6 years ago
Roger, see the noUnwrap logic - this should decide if _isEqual or isEqual is emitted, and looks like it depends on parentCanAvoidUnwrap function in common-progress.rules; check why this function doesn't return true in your when case.
#5 Updated by Roger Borrello over 6 years ago
Constantin Asofiei wrote:
Roger, see the
noUnwraplogic - this should decide if_isEqualorisEqualis emitted, and looks like it depends onparentCanAvoidUnwrapfunction incommon-progress.rules; check why this function doesn't return true in yourwhencase.
Very good hint! :-)
The existing WHEN check was focused on WHEN_LIST/KW_WHEN and KW_COLOR/CONTENT_ARRAY/KW_WHEN. When I added STATEMENT/KW_UNDERLIN/CONTENT_ARRAY/KW_WHEN the correct logical _isEqual is emitted. Thanks! However, I'd still like to know if my code addition could be improved. Is it necessary for me to go all the way back to STATEMENT? The existing code didn't go back that far. Which is best practice?
<!-- WHEN clauses in UI statements -->
<rule>pref.upPath("WHEN_LIST/KW_WHEN") or
pref.upPath("KW_COLOR/CONTENT_ARRAY/KW_WHEN") or
pref.upPath("STATEMENT/KW_UNDERLIN/CONTENT_ARRAY/KW_WHEN")
<action>avoid = true</action>
</rule>
#6 Updated by Greg Shah over 6 years ago
The CONTENT_ARRAY is only found in the MESSAGE, ENABLE, DISABLE, COLOR and UNDERLINE statements, but only COLOR and UNDERLINE can have WHEN clauses. For this reason, it is safe to remove the new code you added and also remove the KW_COLOR:
<!-- WHEN clauses in UI statements -->
<rule>pref.upPath("WHEN_LIST/KW_WHEN") or
pref.upPath("CONTENT_ARRAY/KW_WHEN")
<action>avoid = true</action>
</rule>
#7 Updated by Roger Borrello over 6 years ago
Greg Shah wrote:
The
CONTENT_ARRAYis only found in theMESSAGE,ENABLE,DISABLE,COLORandUNDERLINEstatements, but onlyCOLORandUNDERLINEcan haveWHENclauses. For this reason, it is safe to remove the new code you added and also remove theKW_COLOR:[...]
Made that update, and validated against testcase and customer code.
Check-in 4207a-11357.
#8 Updated by Roger Borrello over 6 years ago
- Status changed from New to WIP
#9 Updated by Greg Shah over 6 years ago
- Status changed from WIP to Test
- % Done changed from 0 to 100
#10 Updated by Roger Borrello over 6 years ago
Task branch 4207a was merged to trunk as revision 11344.
#11 Updated by Greg Shah over 6 years ago
- Status changed from Test to Closed