Skip to content

Generic function creates named class that uses function's type parameter, compiles but fails at runtime #4915

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 Aug 15, 2011 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Aug 15, 2011

This issue is similar to #2144, but here, to avoid compile error, one gives the anonymous class some name. Here is the sample code:

// Bar.scala

def convert[A] = {
  class C {
    def frob(a2: A) = a2
  }
  new C
}

System.out.println(convert[Int].frob(9))

This compiles, but fails in runtime with:

java.lang.NoSuchMethodException: Main$$anon$1$C$1.frob(int)
	at java.lang.Class.getMethod(Class.java:1622)
	at Main$$anon$1.reflMethod$Method1(bug.scala:9)
	at Main$$anon$1.<init>(bug.scala:9)
	at Main$.main(bug.scala:1)
	at Main.main(bug.scala)
@scabug
Copy link
Author

scabug commented Aug 15, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4915?orig=1
Reporter: Arseniy Alekseyev (rotsor)
Affected Versions: 2.9.0-1
See #2144

@scabug
Copy link
Author

scabug commented Aug 15, 2011

@paulp said:
Duplicate of #2672.

@scabug scabug closed this as completed Aug 15, 2011
@scabug
Copy link
Author

scabug commented Aug 15, 2011

Arseniy Alekseyev (rotsor) said:
@paul Phillips, are you sure this is duplicate? This one has nothing to do with structural types.

@scabug
Copy link
Author

scabug commented Aug 15, 2011

@paulp said:
Nothing? What do you think the "refl" in "reflMethod$Method1" means?

The class doesn't have a name by the time you leave the method because it goes out of scope. The type which makes it out is a refinement.

@scabug
Copy link
Author

scabug commented Aug 15, 2011

Arseniy Alekseyev (rotsor) said:
Oh, I see now. Thank you!

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

No branches or pull requests

2 participants