New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated Java generic signature for refinement type incongruous with erasure #9200

Closed
scabug opened this Issue Mar 5, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Mar 5, 2015

% tail sandbox/test.scala sandbox/Main.java
==> sandbox/test.scala <==
trait T1
trait T2 extends T1

object O1 {
    type t = T1 with T2
}

class C1[w<:W](o: O1.t)

class C2 extends T1 with T2

==> sandbox/Main.java <==
public class Main {

    public static void main(String[] args) {
        new C1<>(new C2());
    }
}

% scalac-hash v2.11.5 sandbox/test.scala && javac -classpath .:build/quick/classes/library -d . sandbox/Main.java && scala-hash v2.11.5 Main
java.lang.NoSuchMethodError: C1.<init>(LT1;)V
	at Main.main(Main.java:4)

Reported by Matthieu Leclercq in https://groups.google.com/d/msg/scala-internals/YvWhX3hDavk/BU0cuWHrPG0J

@scabug

This comment has been minimized.

Copy link

scabug commented Mar 5, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9200?orig=1
Reporter: @retronym
Affected Versions: 2.11.6

@scabug

This comment has been minimized.

Copy link

scabug commented Mar 5, 2015

@scabug scabug closed this Mar 26, 2015

@scabug

This comment has been minimized.

Copy link

scabug commented Mar 24, 2016

@retronym said:
Spotted in the wild in static forwarders by [~huntc]

⚡ cat sandbox/test.scala && scalac -Xprint:typer sandbox/test.scala && javap -s C
trait T[A]
object C {
  def foo: T[Any] = new T[Any] {}
  def baz = new T[Any] {}
}


[[syntax trees at end of                     typer]] // test.scala
package <empty> {
  abstract trait T[A] extends scala.AnyRef;
  object C extends scala.AnyRef {
    def <init>(): C.type = {
      C.super.<init>();
      ()
    };
    def foo: T[Any] = {
      final class $anon extends AnyRef with T[Any] {
        def <init>(): <$anon: T[Any]> = {
          $anon.super.<init>();
          ()
        };
        <empty>
      };
      new $anon()
    };
    def baz: T[Any] = {
      final class $anon extends AnyRef with T[Any] {
        def <init>(): <$anon: T[Any]> = {
          $anon.super.<init>();
          ()
        };
        <empty>
      };
      new $anon()
    }
  }
}

Compiled from "test.scala"
public final class C {
  public static java.lang.Object baz();
    descriptor: ()LT;

  public static T<java.lang.Object> foo();
    descriptor: ()LT;
}
/code/scala2 on review/4971*
⚡ cat sandbox/test.scala && scalac -Ydebug -Xprint:typer sandbox/test.scala && javap -s C
trait T[A]
object C {
  def foo: T[Any] = new T[Any] {}
  def baz = new T[Any] {}
}


[running phase parser on test.scala]
[running phase namer on test.scala]
[running phase packageobjects on test.scala]
[running phase typer on test.scala]
[[syntax trees at end of                     typer]] // test.scala
package <empty> {
  <interface> abstract <defaultparam/trait> trait T[A] extends scala.AnyRef;
  <module> object C extends scala.AnyRef {
    <method> def <init>(): <empty>.this.C.type = {
      C.super.<init>();
      ()
    };
    <method> def foo: <empty>.this.T[scala.this.Any] = {
      final class $anon extends scala.this.AnyRef with <empty>.this.T[scala.this.Any] {
        <method> <triedcooking> def <init>(): <$anon: <empty>.this.T[scala.this.Any]> = {
          $anon.super.<init>();
          ()
        };
        <empty>
      };
      new $anon.<init>()
    };
    <method> def baz: <empty>.this.T[scala.this.Any]{} = {
      final class $anon extends scala.this.AnyRef with <empty>.this.T[scala.this.Any] {
        <method> <triedcooking> def <init>(): <$anon: <empty>.this.T[scala.this.Any]> = {
          $anon.super.<init>();
          ()
        };
        <empty>
      };
      new $anon.<init>()
    }
  }
}

[running phase patmat on test.scala]
[running phase superaccessors on test.scala]
[running phase extmethods on test.scala]
[running phase pickler on test.scala]
[running phase refchecks on test.scala]
[running phase uncurry on test.scala]
[running phase tailcalls on test.scala]
[running phase specialize on test.scala]
[running phase explicitouter on test.scala]
[running phase erasure on test.scala]
[running phase posterasure on test.scala]
[running phase lazyvals on test.scala]
[running phase lambdalift on test.scala]
[running phase constructors on test.scala]
[running phase flatten on test.scala]
[running phase mixin on test.scala]
[running phase cleanup on test.scala]
[running phase delambdafy on test.scala]
[running phase icode on test.scala]
[running phase jvm on icode]
Compiled from "test.scala"
public final class C {
  public static java.lang.Object baz();
    descriptor: ()LT;

  public static T<java.lang.Object> foo();
    descriptor: ()LT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment