groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8321) !instanceof treated incorrectly in type checker
Date Sat, 16 Sep 2017 04:07:00 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-8321?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Paul King updated GROOVY-8321:
------------------------------
    Description: 
Currently in:
https://github.com/apache/groovy/blob/183b8fbf0248a2dceffbba684e50c3c2c060e46c/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L703

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`.

{code}
[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'
  }
}
{code}
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.

  was:
Currently in:
https://github.com/apache/groovy/blob/183b8fbf0248a2dceffbba684e50c3c2c060e46c/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L703

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`.

{code}
[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'
  }
}
{code}
We'd now expect the `toUpperCase` call to fail but is succeeds.

Bonus points if the commented line in the else clause can be made to work.


> !instanceof treated incorrectly in type checker
> -----------------------------------------------
>
>                 Key: GROOVY-8321
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8321
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.6.0-alpha-1
>            Reporter: Paul King
>
> Currently in:
> https://github.com/apache/groovy/blob/183b8fbf0248a2dceffbba684e50c3c2c060e46c/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java#L703
> 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`. 
> {code}
> [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'
>   }
> }
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message