Skip to content

Compilation error with context bounds #1259

Open
@NTPape

Description

@NTPape

Hello there!

Compilation of the following code will fail

import monocle.Lens
import monocle.macros.GenLens

trait Foo[T]
trait Bar[T]

case class A[T: Foo](s: A.S[T]) {
  private val lens: Lens[A.S[T], Bar[T]] = GenLens[A.S[T]](_.bar)
}

object A {
  case class S[T: Foo](bar: Bar[T])
}

in Scala 3 with the following error

[error] 8 |  private val lens: Lens[A.S[T], Bar[T]] = GenLens[A.S[T]](_.bar)
[error]   |                                           ^^^^^^^^^^^^^^^^^^^^^^
[error]   |Exception occurred while executing macro expansion.
[error]   |java.lang.Exception: Expected an expression. This is a partially applied Term. Try eta-expanding the term first.

and in Scala 2.13 with

[error] could not find implicit value for evidence parameter of type Foo[T]
[error]   private val lens: Lens[A.S[T], Bar[T]] = GenLens[A.S[T]](_.bar)
[error]                                                           ^

Interestingly, the last version that appears to work is 1.5.1-cats on Scala 2.11 (but not on Scala 2.12.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions