Code: Select all
v := 00
Switch v
{
case "0": ToolTip, 1
case "00": ToolTip, 2
}
return
Code: Select all
v := 00
if (v = "0")
ToolTip, 1
else if (v = "00")
ToolTip, 2
return
Code: Select all
v := 00
Switch v
{
case "0": ToolTip, 1
case "00": ToolTip, 2
}
return
Code: Select all
v := 00
if (v = "0")
ToolTip, 1
else if (v = "00")
ToolTip, 2
return
Code: Select all
case "0"
Then explain the result of the second script.niCode wrote: ↑ In the first example,is comparing to a string but you set the v variable to an integer.Code: Select all
case "0"
What should I have done?niCode wrote: ↑26 Oct 2022, 18:09In the first example,is comparing to a string but you set the v variable to an integer.Code: Select all
case "0"
but i think that's bug you mean switch use inStr ?boiler wrote: ↑26 Oct 2022, 18:51Then explain the result of the second script.niCode wrote: ↑ In the first example,is comparing to a string but you set the v variable to an integer.Code: Select all
case "0"
Code: Select all
df := 00
Switch (001234)
{
Case "01234": ToolTip, 1
Case "001234": ToolTip, 2
}
Code: Select all
df := 001234
Switch (df)
{
Case "01234": ToolTip, 1
Case "001234": ToolTip, 2
}
Code: Select all
a := 00
b := "0"
MsgBox % (a = b) ; 1
lexikos wrote: ↑27 Oct 2022, 22:40When posting a bug report, code to reproduce the issue, a description (even a brief one) of your expectations and what results you are getting should be the bare minimum that you provide. This bug report is lacking two of those things - arguably all of them, if you consider that the tooltip never displays because the script exits immediately.
I think that mixing both unquoted literal numbers and quoted literal strings within the same switch not only fails to show your intent (do you intend numeric or non-numeric evaluation?), but might indicate that you are not considering that a distinction needs to be made in the first place. Instead, it seems you are expecting the language to implicitly understand what you are trying to do despite mixed signs of intent.
One might expect switch (00)..case "0": to be consistent with if (00 = "0"), but these values are evaluated individually, at different times. Consider this:Which behaviour is correct or most intuitive for Switch cannot be decided based purely on how the expression operators behave. Inconsistency within the type system is a fundamental problem of v1, not just Switch.Code: Select all
a := 00 b := "0" MsgBox % (a = b) ; 1
Ignoring how the switch value is expressed, it would be reasonable to assume that case "0": is intended to compare a string, since a number should have been expressed as case 0:. It doesn't currently work that way because Switch was primarily designed for v2, where the types of the input values have less ambiguity.
Changing Switch to always perform string comparison for case "0": seems to be the simplest solution, although it would perpetuate a legacy quirk of v1 that does not apply to v2 (where (0 = "00") and v := 00..switch v..case "0": use numeric comparison because v is a pure number). Changing it to behave exactly as in v2 would not be feasible because it would depend on broader changes to the type system that have a high risk of breaking scripts. Since the current behaviour is already inconsistent with v2 and is less flexible, perhaps the simple solution is acceptable.
On the other hand, back-porting the CaseSense parameter of Switch would provide a clear and unambiguous way to ensure that all of the values are compared as strings.
Of less importance, the current documentation of Switch in v1 does not specify how the comparisons are made. The current behaviour is compliant with the documentation.
Code: Select all
df := 001234
Switch (df)
{
Case "01234": ToolTip, 1
Case "001234": ToolTip, 2
}
thanks dude butlexikos wrote: ↑27 Oct 2022, 22:40When posting a bug report, code to reproduce the issue, a description (even a brief one) of your expectations and what results you are getting should be the bare minimum that you provide. This bug report is lacking two of those things - arguably all of them, if you consider that the tooltip never displays because the script exits immediately.
I think that mixing both unquoted literal numbers and quoted literal strings within the same switch not only fails to show your intent (do you intend numeric or non-numeric evaluation?), but might indicate that you are not considering that a distinction needs to be made in the first place. Instead, it seems you are expecting the language to implicitly understand what you are trying to do despite mixed signs of intent.
One might expect switch (00)..case "0": to be consistent with if (00 = "0"), but these values are evaluated individually, at different times. Consider this:Which behaviour is correct or most intuitive for Switch cannot be decided based purely on how the expression operators behave. Inconsistency within the type system is a fundamental problem of v1, not just Switch.Code: Select all
a := 00 b := "0" MsgBox % (a = b) ; 1
Ignoring how the switch value is expressed, it would be reasonable to assume that case "0": is intended to compare a string, since a number should have been expressed as case 0:. It doesn't currently work that way because Switch was primarily designed for v2, where the types of the input values have less ambiguity.
Changing Switch to always perform string comparison for case "0": seems to be the simplest solution, although it would perpetuate a legacy quirk of v1 that does not apply to v2 (where (0 = "00") and v := 00..switch v..case "0": use numeric comparison because v is a pure number). Changing it to behave exactly as in v2 would not be feasible because it would depend on broader changes to the type system that have a high risk of breaking scripts. Since the current behaviour is already inconsistent with v2 and is less flexible, perhaps the simple solution is acceptable.
On the other hand, back-porting the CaseSense parameter of Switch would provide a clear and unambiguous way to ensure that all of the values are compared as strings.
Of less importance, the current documentation of Switch in v1 does not specify how the comparisons are made. The current behaviour is compliant with the documentation.
I thought the same but I tried it and didn't work, that's a fix for v2, not for v1.
Code: Select all
v := "00"
Switch v
{
case "0": Msgbox 1 ; v1
case "00": Msgbox 2 ; v2
}
Code: Select all
v := "00"
Switch "|" v
{
case "|0": Msgbox 1
case "|00": Msgbox 2
}
either use the workaround boiler posted
Code: Select all
v := "00"
(v = "0") ? MsgBox("1")
: (v = "00") ? MsgBox("2")
return
MsgBox(str) {
MsgBox, %str%
}
Code: Select all
v := "000"
Switch 1
{
case (v="000"): Msgbox 3
case (v="0"): Msgbox 1
case (v="00000"): Msgbox 5
case (v="00"): Msgbox 2
case (v="0000"): Msgbox 4
}
Code: Select all
v := 00
switch v
{
case "0": MsgBox 1
case "00": MsgBox 2
}