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-8237) Invalid type inference when using CompileStatic annotation
Date Thu, 21 Sep 2017 00:19:00 GMT

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

Paul King updated GROOVY-8237:
------------------------------
    Description: 
With Groovy 2.4.12 the following snippet report an error 

{code}
@groovy.transform.CompileStatic
class Foo {

  String parse(Reader reader) {
        if ( reader == null ) {  // != works okay
          reader = new BufferedReader(reader)
        }
         
        def c 
        while ((c = reader.read()) != -1) 
           print c as char
  }
}

new Foo().parse( new StringReader('abc') )
{code}

The following exception is thrown 

{code}
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'java.io.StringReader@7a636960'
with class 'java.io.StringReader' to class 'java.io.BufferedReader'
{code}

  was:
With Groovy 2.4.12 the following snippet report an error 

{code}
@groovy.transform.CompileStatic
class Foo {

  String parse(Reader reader) {
        if ( reader == null ) {
          reader = new BufferedReader(reader)
        }
         
        def c 
        while ((c = reader.read()) != -1) 
           print c as char
  }
}

new Foo().parse( new StringReader('abc') )
{code}

The following exception is thrown 

{code}
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'java.io.StringReader@7a636960'
with class 'java.io.StringReader' to class 'java.io.BufferedReader'
{code}


> Invalid type inference when using CompileStatic annotation
> ----------------------------------------------------------
>
>                 Key: GROOVY-8237
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8237
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.12
>            Reporter: paolo di tommaso
>
> With Groovy 2.4.12 the following snippet report an error 
> {code}
> @groovy.transform.CompileStatic
> class Foo {
>   String parse(Reader reader) {
>         if ( reader == null ) {  // != works okay
>           reader = new BufferedReader(reader)
>         }
>          
>         def c 
>         while ((c = reader.read()) != -1) 
>            print c as char
>   }
> }
> new Foo().parse( new StringReader('abc') )
> {code}
> The following exception is thrown 
> {code}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'java.io.StringReader@7a636960'
with class 'java.io.StringReader' to class 'java.io.BufferedReader'
> {code}



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

Mime
View raw message