According to JLS, the grammer of basic for statement is
for ( [ForInit] ; [Expression] ; [ForUpdate] ) Statement
It's also said on the JLS that 'The Expression must have type boolean or Boolean , or a compile-time error occurs.'
So to check if the syntax is valid, the parser check the code against the EBNF grammer. But the grammer doesn't specify that the [Expression] has to return boolean/Boolean value - then how does a compiler catchs that the expression isn't returning boolean during compile time?