TriggerReactor

TriggerReactor

24.6k Downloads

Inconsistent behavior of literal string "true"/"false"

Sayakie opened this issue ยท 4 comments

commented

๐Ÿ› 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

An example case 1 about this issue which prints only wrong behavior message

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

An example case 2 about this issue which prints only wrong behavior message

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

commented

if ("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;
}

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.

commented

@wysohn, I have a question, should we have to put this and #471 to In progress or Beta?

commented

@wysohn, I have a question, should we have to put this and #471 to In progress or Beta?

I would say put the PR into the Beta and take #471 out of the board (and maybe close it)

commented

Confirmed :D