Skip to content
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

Calling dependent method type causes AbstractMethodError #6135

Closed
scabug opened this issue Jul 24, 2012 · 3 comments
Closed

Calling dependent method type causes AbstractMethodError #6135

scabug opened this issue Jul 24, 2012 · 3 comments

Comments

@scabug
Copy link

@scabug scabug commented Jul 24, 2012

This issue shows up when calling abstract dependent method types declared within generic classes. The class generic parameter must appear somewhere in the method signature. For instance:

> class A{ class V }; val a1 = new A; val v1 = new a1.V
...
> abstract class B[S]{ def f(t: S, a: A)(v: a.V) }
...
> val b1 = new B[String]{ def f(t: String, a: A)(v: a.V) = println("ok!") }
...
> b1.f("",a1)(v1)
java.lang.AbstractMethodError: B.f(Ljava/lang/Object;LA;LA$V;)V
	at .<init>(<console>:13)
	at .<clinit>(<console>)
        ...

I found similar problems when the parameter S appears in other locations of the method signature, i.e. the compiler also complains when f is declared either as f1 or f2 (see bellow). However, there is no problem whatsoever when the parameter is not part of the declaration, as in f3:

def f1(a: A)(t: S, v: a.V)
def f2(a: A)(v: a.V): S
def f3(a: A)(v: a.V)

Still, we can get f be called successfully if object b1 is created through an object declaration:

> object b1 extends B[String]{ def f(t: String, a: A)(v: a.V) = println("ok!") }
...
> b1.f("",a1)(v1)
ok!

but the problem persists when f is called through a generic function or other generic class (including B[S] itself). For instance:

scala> def f[S](b: B[S], t: S, a: A)(v: a.V) = b.f(t,a)(v)
...
scala> f(b1,"",a1)(v1)
java.lang.AbstractMethodError: B.f(Ljava/lang/Object;LA;LA$V;)V
	at .f(<console>:9)
	at .<init>(<console>:14)
        ...

I couldn't find a proper workaround. Tried these but don't work either:

def f(t: S, a: At)(e: T[a.type]) // given another definition of T 
def f(t: S, a: At): a.T => Unit

The last one doesn't even compile when B[String] is instantiated, showing an strange message:

> object b1 extends B[String]{ def f(a: A) = (v: a.V) => println("ok!") }
<console>:9: error: type mismatch;
 found   : a.V => Unit
 required: a.V => Unit
 possible cause: missing arguments for method or constructor
       object b1 extends B[String]{ def f(a: A) = (v: a.V) => println("ok!") }
@scabug
Copy link
Author

@scabug scabug commented Jul 24, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6135?orig=1
Reporter: Juan Manuel Serrano (jserrano)
Affected Versions: 2.9.1, 2.10.0-M5

@scabug
Copy link
Author

@scabug scabug commented Dec 3, 2012

@scabug
Copy link
Author

@scabug scabug commented Jan 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants