question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot generate an implementation for parameterized traits

See original GitHub issue

Lagom Version 1.3.4 Scala API, with Scala 2.12.2 OpenJDK 64-Bit Server VM (Zulu 8.20.0.5-macosx) (build 25.121-b15, mixed mode)

Expected Behavior

With these traits

trait GenericService[T] extends Service {
  def get(id: String, t: T): ServiceCall[NotUsed, T]
  def baseDescriptor(name: String)(implicit ft: Format[T], pt: PathParamSerializer[T]) =
    named(name).withCalls(
      pathCall( s"/api/$name/get/:id/:t", this.get _ ))
}

trait StringService extends GenericService[String] {
  override def descriptor = baseDescriptor("String")
}

I would expect this to compile

  val stringService = serviceClient.implement[StringService]

Actual Behavior

However, it produces this error

object creation impossible, since method get in trait GenericService of type (id: String, t: String)com.lightbend.lagom.scaladsl.api.ServiceCall[akka.NotUsed,String] is not defined

It would be nice if type parameters were supported, as it would allow to factor out similarities between a few services into a common base trait.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
octonatocommented, Jun 8, 2017

Thanks @crfeliz I will have a look into that.

0reactions
patrick-premontcommented, Jun 15, 2017

My use case does not exactly relate to endpoints generated from another tool. Those would likely have distinct methods of the same form, but I don’t think it would be possible to write a generic descriptor for those.

It relates to services that have similar interfaces and for which we can rely on inheritance to share parts of the interface and implementation. More concretely, I have a polymorphic repository class that I want to put behind a service layer, and that would lead the services to be mostly identical (especially the read-only methods that do not need to do validation).

Since Lagom does not support it currently, I have opted to duplicate the methods, so I do not have an urgent need for it anymore. Still, if it’s not too challenging, I think it would be nice to allow for this.

Perhaps eventually I will want to move many of my similar methods into a single service, and then even a solution to the present issue would not allow me to reuse code. I would then need reuse through aggregation (nested service traits) instead of inheritance, which is a whole other story.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rust - How to implement a trait for a parameterized trait
I cannot implement trait for this trait due to E207 error ("the type parameter K is not constrained by the impl trait, self...
Read more >
E0038 - Error codes index
Attempting to use a trait object type for a trait that is not object-safe will trigger error E0038.
Read more >
Advanced Traits - The Rust Programming Language
In other words, when a trait has a generic parameter, we can implement that trait for a type multiple times, changing the generic...
Read more >
Traits in Rust - Serokell
Traits describe an interface that types can implement. ... Trait instance method has // [2]: the **&self** parameter as the first parameter; ...
Read more >
Value Classes and Universal Traits - Scala Documentation
It has a single, public val parameter that is the underlying runtime ... A value class can only extend universal traits and cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found