Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Inconsistency in Generic derivation for non-case classes? #934

Closed
alexarchambault opened this issue Oct 28, 2019 · 1 comment · Fixed by #972
Closed

Inconsistency in Generic derivation for non-case classes? #934

alexarchambault opened this issue Oct 28, 2019 · 1 comment · Fixed by #972
Labels

Comments

@alexarchambault
Copy link
Collaborator

I'm getting the following when deriving (or trying to) Generic instances for non-case classes:

import shapeless.Generic

object Test {
  final class Foo(val n: Int)
  final class FooWithVal(val n: Int) {
    val isEven = n % 2 == 0
  }

  val fooGen = Generic[Foo] // works
  val fooWithValGen = Generic[FooWithVal] // fails, see error below
}

fails with

Test.scala:13:30: could not find implicit value for parameter gen: shapeless.Generic[Test.FooWithVal]
  val fooWithValGen = Generic[FooWithVal]
                             ^

So adding a val field in the body of a non-case class that Generic accepts, makes Generic reject it.

Is that intended somehow?

Just checking if that's expected or not, I can submit a fix for that.

@milessabin
Copy link
Owner

It's falling foul of the logic which attempts to handle by-name constructor arguments. Ideally we'd like to be able to support,

class Foo(i0: => Int) {
  lazy val i: Int = i0
}

In this case we want the lazy val i in the body to be treated as the product element. There's a relevant test here. A fix would be lovely, so long as it doesn't break that one.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants