groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniil Ovchinnikov (JIRA)" <j...@apache.org>
Subject [jira] [Created] (GROOVY-8757) Incorrect bytecode produced after compiling class implementing trait with generic method
Date Mon, 20 Aug 2018 17:23:00 GMT
Daniil Ovchinnikov created GROOVY-8757:
------------------------------------------

             Summary: Incorrect bytecode produced after compiling class implementing trait
with generic method
                 Key: GROOVY-8757
                 URL: https://issues.apache.org/jira/browse/GROOVY-8757
             Project: Groovy
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 3.0.0-alpha-3, 2.4.15
            Reporter: Daniil Ovchinnikov


{code:java|title=T.groovy}
trait T {
    def <T extends Number> T foo(Class<T> c) {
        println c
        return null 
    }
}
{code}
{code:java|title=C.groovy}
class C implements T {}
{code}
{code:java|title=usage.groovy}
new C().foo(Integer)
{code}
{noformat}
$ groovyc C.groovy T.groovy
$ groovy usage.groovy
class java.lang.Integer
$ groovyc C.groovy # recompile C using already compiled T
$ groovy usage.groovy
Caught: java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    C.foo(Ljava/lang/Class;)Ljava/lang/Number; @5: areturn
  Reason:
    Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'java/lang/Number'
(from method signature)
  Current Frame:
    bci: @5
    flags: { }
    locals: { 'C', 'java/lang/Class' }
    stack: { 'java/lang/Object' }
  Bytecode:
    0x0000000: 2a2b b600 88b0

java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    C.foo(Ljava/lang/Class;)Ljava/lang/Number; @5: areturn
  Reason:
    Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'java/lang/Number'
(from method signature)
  Current Frame:
    bci: @5
    flags: { }
    locals: { 'C', 'java/lang/Class' }
    stack: { 'java/lang/Object' }
  Bytecode:
    0x0000000: 2a2b b600 88b0

	at usage.run(usage.groovy:1)
{noformat}

{noformat:title=original javap output}
public class C implements T,groovy.lang.GroovyObject {
  public static transient boolean __$stMC;
  public C();
  public <T extends java.lang.Number> T foo(java.lang.Class<T>);
  public <T extends java.lang.Number> T Ttrait$super$foo(java.lang.Class<T>);
  static {};
  protected groovy.lang.MetaClass $getStaticMetaClass();
  public groovy.lang.MetaClass getMetaClass();
  public void setMetaClass(groovy.lang.MetaClass);
  public java.lang.Object invokeMethod(java.lang.String, java.lang.Object);
  public java.lang.Object getProperty(java.lang.String);
  public void setProperty(java.lang.String, java.lang.Object);
}
{noformat}

{noformat:title=recompiled javap output}
public class C implements T,groovy.lang.GroovyObject {
  public static transient boolean __$stMC;
  public C();
  public <T> T foo(java.lang.Class<T>);
  public <T extends java.lang.Number> T Ttrait$super$foo(java.lang.Class<T>);
  static {};
  protected groovy.lang.MetaClass $getStaticMetaClass();
  public groovy.lang.MetaClass getMetaClass();
  public void setMetaClass(groovy.lang.MetaClass);
  public java.lang.Object invokeMethod(java.lang.String, java.lang.Object);
  public java.lang.Object getProperty(java.lang.String);
  public void setProperty(java.lang.String, java.lang.Object);
  public java.lang.Number foo(java.lang.Class);
}
{noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message