Inconsistent behavior of literal string "true"/"false"
Sayakie opened this issue ยท 4 comments
๐ Bug Report
The following example script code will be throw an exception that does not exist or parameter types not match. Because the variable temp
would be parsed as Boolean type.
temp = "true"
FOR c = temp.getBytes()
#MESSAGE c
ENDFOR
More examples below:
Case 1.
Else branch never be executed.
temp = "true"
IF temp == true
#MESSAGE "Wrong behavior! :("
ELSE
#MESSAGE "We expected this behavior! :D"
ENDIF
Case 2.
Also else branch never be reached.
IMPORT java.lang.Boolean
IF "true" IS Boolean
#MESSAGE "Wrong behavior! :("
ELSE
#MESSAGE "We expected this behavior! :D"
ENDIF
This behavior can lead to serious confusion later on.
Test Environments
- Server Info: CatServer 1.12.2 (Build based on Luohuayu/CatServer@a8b73e9)
- Minecraft Version: 1.12.2
- TriggerReactor Version: TriggerReactor Bukkit-legacy 3.3.0.6-beta
- See also: #471
We must add Token type-check logic in order to make sure for Parser to work as intended.
--- if ("true".equals(token.value) || "false".equals(token.value)) {
+++ if (token.type == Type.ID && ("true".equals(token.value) || "false".equals(token.value))) {
Node node = new Node(new Token(Type.BOOLEAN, token.value, token.row, token.col));
nextToken();
return node;
}
Reworked code will be parse literal string "true" as String type, not Boolean type.