Skip to content

private method names are unnecessarily slippery #2840

Closed
@scabug

Description

@scabug

Consider these two classes:

class S {
  private def foo(x: Int) = x*x
}
class S2 {
  private def foo(x: Int) = x*x
  
  def bar = 1 to 5 map foo
}

And the generated code:

// S1
private int foo(int);
// S2
public final int S2$$$$foo(int);

I realize that in S2 a public method must be created so S2$$$$anonfun$$bar$$1 can access it, however I propose the original private method ought to be generated as well, simply forwarding to the public method.

This came up because I'm spending time porting various java tools to scala in parallel with working on a bytecode library. People use reflection in all manner of interesting ways, among them calling getDeclaredMethod (which considers private methods) expecting to find a method with the same name as the one in the source. Seems like a reasonable expectation.

I realize there will most likely be situations where scala bytecode can't be as predictable as java, however this doesn't like one of them.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions