class Main {
function void main() {
var #type# a;
let a = null; // line 4
let a = 0; // line 5
let a = 1; // line 6
let a = true; // line 7
let a = false + a; // line 8
return;
}
}
When #type# = Array, there are no errors.
When #type# = int, errors are following:
In Main.jack (line 3): In subroutine main: an int value is expected
In Main.jack (line 6): In subroutine main: an int value is expected
In Main.jack (line 8): In subroutine main: An int value is illegal here
In Main.jack (line 7): In subroutine main: an int value is expected
When #type# = boolean, error is following:
In Main.jack (line 3): In subroutine main: a boolean value is expected
So far, it seems that:
* If expression involves object type, almost no type checking is performed
* null can be assigned only to object type variable
* It is illegal to assign true/false to int variable, but it is legal to assign integer constant to boolean variable
It seems that provided JACK compiler have very arbitrary type rule and have no common pattern.
When I implement my own JACK compiler, I almost ignore "type rules" and treat null / true / false as same as constant 0 / -1 / 0. Now I'm not sure that it was my best :(