Implement a polymorphic method #15299
Unanswered
gregghz
asked this question in
Metaprogramming
Replies: 1 comment 1 reply
-
The issue is that type parameters are unique for each method, so should not be shared. In your example, you are reusing the type for Currently in |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've created a macro that takes a type parameter (referencing a trait) and attempts to create an implementation of that trait.
That is, calling:
make[TestTrait]
should produce a class that implementsTestTrait
. However, so far, I am unable to implement polymorphic methods.TestTrait
has this abstract method:def poly[A](x: List[A]): A
and I want the implementation created via the macro to just callx.head
.My attempt at this is here: https://gist.github.com/gregghz/6b74e50c1600c30322403449ce978a8c
The code produced looks how I'd expect/want with a class defined and an override for poly that looks like this:
However, the compilation fails with an error saying that my class needs to be abstract because
poly
is not defined. The error says that my override does not match because their type parameters differ even though the compiler output shows them side by side and they look identical:Can anyone point me in the right direction here?
Beta Was this translation helpful? Give feedback.
All reactions