Skip to content

java generic signature of a class should not refer to type parameters of an enclosing method #3249

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

Closed
scabug opened this issue Apr 3, 2010 · 13 comments
Assignees

Comments

@scabug
Copy link

scabug commented Apr 3, 2010

I am using 2.8.0.r21010-b2010022802013

This problem affects all scala classiles I have tried.
It can be reproduced on the scala-library classes, eg:

$$ javac -cp scala-library.jar -Xprint scala.actors.Actor
error: cannot access scala.actors.Actor.$$anonfun$$receiveWithin$$1
class file for scala.actors.Actor$$$$anonfun$$receiveWithin$$1 not found
1 error

I believe this needs to work in order to process java classfile annotations in scala classfiles (ie by using -processor instead of -Xprint)

@scabug
Copy link
Author

scabug commented Apr 3, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3249?orig=1
Reporter: Daniel Mahler (mahler)

@scabug
Copy link
Author

scabug commented Apr 4, 2010

@paulp said:
This is some kind of companion unhappiness. In the example above you are giving scala.actors.Actor, but the class it's complaining about is a member of scala.actors.Actor$$, not Actor. It looks like it happens pretty easily.

% cat a.scala 
object A { def f[T] = (x: T) => 5 }

% scalac a.scala 
% javac -cp .:scala-library.jar -Xprint 'A$$'
public final class A$$ implements scala.ScalaObject {
  public static final A$$ MODULE$$;

  public <T> scala.Function1<T,java.lang.Integer> f();

  private A$$();
}
% javac -cp .:scala-library.jar -Xprint 'A'
error: cannot access A.$$anonfun$$f$$1
bad class file: ./A$$$$anonfun$$f$$1.class
undeclared type variable: T
Please remove or make sure it appears in the correct subdirectory of the classpath.
1 error

@scabug
Copy link
Author

scabug commented Jun 4, 2010

@adriaanm said:
It's actually local-generic-classes-that-refer-to-the-method's-type-parameter unhappiness (granted, not as catch as companion unhappiness -- to compensate, reduced it to a one-liner):

// a.scala
class A[U] { def f[T] = { class X extends A[T] } }


/*
$$ scalac a.scala
$$ javac -cp .:$$SCALA_HOME/lib/scala-library.jar  -Xprint 'A$$X$$1'

    public class X$$1 extends A</*OHNOES where is T!1?*/> implements scala.ScalaObject {
      public X$$1();
    }

*/

@scabug
Copy link
Author

scabug commented Jun 4, 2010

@adriaanm said:
I'm sure there are more cases where we generate javasigs that aren't up to snuff
part of the problem is I don't know what the spec of these things is (there is some obscure pdf by sunacle that Iulian pointed me to)
another aspect is that we can't test these things using partest (yet)
need to compile a scala file, then run javac -Xprint on all the generated classes and ensure the sigs are ok

for this example, and class A$$X$$1, the fix for this ticket ensures it looks like (note the null for the outer pointer argument's name...)

$$ scalac a.scala
$$ javac -cp .:$$SCALA_HOME/lib/scala-library.jar  -Xprint 'A$$X$$1'

  public class X$$1 extends A<java.lang.Object> implements scala.ScalaObject {
    public X$$1(A<U> null);
  }

@scabug
Copy link
Author

scabug commented Jun 4, 2010

@adriaanm said:
related to #3486 in that they require similar kind of testing

@scabug
Copy link
Author

scabug commented Jul 8, 2010

@adriaanm said:
(In r22511) closes #3249. exclude method type parameters from java generic signature of a class
review by dragos

@scabug
Copy link
Author

scabug commented Aug 27, 2010

@adriaanm said:
from #3801:

javac -cp experimental/users/mahler/scala/scala-2.8.0.r22830-b20100824020153/lib/scala-library.jar -Xprint scala.actors.Actor error: cannot access scala.actors.Actor.$$anonfun$$respondOn$$1 bad class file: scala/actors/Actor$$$$anonfun$$respondOn$$1.class(scala/actors:Actor$$$$anonfun$$respondOn$$1.class) undeclared type variable: A Please remove or make sure it appears in the correct subdirectory of the classpath. 1 error

@scabug
Copy link
Author

scabug commented Sep 3, 2010

@adriaanm said:
Iulian, re-assigning to you as you know more about this stuff -- feel free to bounce it back
(oh, and you reviewed my original fix, so you probably saw this coming ;-p)

@scabug
Copy link
Author

scabug commented Sep 3, 2010

Josh Suereth (joshua.suereth) said:
I wanted to add that this eclipse bug seems particularly relevant: https://bugs.eclipse.org/bugs/show_bug.cgi?id=101794

@scabug
Copy link
Author

scabug commented Sep 3, 2010

Josh Suereth (joshua.suereth) said:
So... this one is a bit subtle. It looks like the rule of 3 applies here. If I have a generic class with a generic method, then I need a third method that also has generics to get the invalid signature. Here's my simplifying from Option what will cause the problematic classfile to be generated:

class A[U] { 
   def bar[B >: U](x : => B) = x
   def foo[C >: U](c : C) : C = bar(c)
}

Leads to the ever-so-helpful message:

jsuereth@jsuereth-laptop:~/projects/blog/type-fun$$ scalac dummy.scala 
jsuereth@jsuereth-laptop:~/projects/blog/type-fun$$ javac -cp .:/home/jsuereth/projects/scala/scala/build/quick/classes/library/ -Xprint A
error: cannot access A.$$anonfun$$foo$$1
bad class file: ./A$$$$anonfun$$foo$$1.class
undeclared type variable: C
Please remove or make sure it appears in the correct subdirectory of the classpath.
1 error

I tried reproducing without having the extra method and was unable to. Something about the generic method that is auto-lifting the closure for another generic method is bypassing the logic Adrian added. If you'd like me to some more investigated here, please let me know.

@scabug
Copy link
Author

scabug commented Nov 12, 2010

@dragos said:
(In r23503) Generate EnclosingMethod classfile attributes.
This should fix java signatures when they refer to
method type parameters. I unrolled Adriaans previous fix
for #3249, as this one is more general. Closes #3249,
review by moors.

@scabug
Copy link
Author

scabug commented Nov 13, 2010

@dragos said:
It turns out it breaks for top level objects. It has a lot more implications than I first thought. Opening again, this one needs more work.

@scabug
Copy link
Author

scabug commented Nov 14, 2010

@dragos said:
Fixed in r23507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants