Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
The `instanceof` and `!instanceof` operators are treated the same when in fact the exact opposite is required.
Consider the following code where the `instanceof` has been accidentally replaced with `!instanceof`.
[42, 'bar'].each { doit(it) } @groovy.transform.TypeChecked doit(arg) { if (arg !instanceof String) { println arg.toUpperCase() // MME: Integer.toUpperCase() } else { // println arg.toUpperCase() // [STC] [Static type checking] - Cannot find Object#toUpperCase() println 'is a number' } }
We'd now expect the `toUpperCase` call to fail compilation but it succeeds and then fails at runtime.
Bonus points if the commented line in the else clause can be made to work.
Attachments
Issue Links
- is related to
-
GROOVY-8523 Static type checking instanceof
- Closed