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

Type aliases and Focus are not friends in scala 3 #1177

Closed
romainreuillon opened this issue Jul 15, 2021 · 1 comment · Fixed by #1178
Closed

Type aliases and Focus are not friends in scala 3 #1177

romainreuillon opened this issue Jul 15, 2021 · 1 comment · Fixed by #1178
Labels

Comments

@romainreuillon
Copy link

Dear Devs,

using monocle 3.0.0 and scala 3.0.1-RC2

Using Focus on type aliases with type parameter seem to pose some problems to monocle 3.0.0.

For instance, this code

import monocle._

object Test {

  case class CC[T](t: T, i: Int)

  type CCInt = CC[Int]

  val cc = CC(2, 3)
  Focus[CCInt](_.i).get(cc)
}

Raises the following error message:

[error] -- Error: /tmp/bugmonocle/Test.scala:11:2 --------------------------------------
[error] 11 |  Focus[CCInt](_.i).get(cc)
[error]    |  ^^^^^^^^^^^^^^^^^
[error]    |  method copy in class CC does not take parameters
[error]    | This location contains code that was inlined from Test.scala:11

And this code:

import monocle._

object Test {

  case class CC[T](t: T, i: Int)

  type CCInt = CC[Int]

  val cc = CC(2, 3)
  Focus[CCInt](_.t).get(cc)
}

Raises this error message:

[error] -- Error: /tmp/bugmonocle/Test.scala:11:14 -------------------------------------
[error] 11 |  Focus[CCInt](_.t).get(cc)
[error]    |  ^^^^^^^^^^^^^^^^^
[error]    |Exception occurred while executing macro expansion.
[error]    |java.lang.Exception: Expr cast exception: from.t
[error]    |of type: from.t
[error]    |did not conform to type: CC.this.T
[error]    |
[error]    |	at scala.quoted.runtime.impl.QuotesImpl.asExprOf(QuotesImpl.scala:71)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:113)
[error]    |	at scala.quoted.runtime.impl.QuotesImpl$reflect$TreeMethods$.asExprOf(QuotesImpl.scala:112)
[error]    |	at monocle.internal.focus.features.selectfield.SelectFieldGenerator.generateSelectField$$anonfun$8(SelectFieldGenerator.scala:25)
[error]    |	at monocle.internal.focus.features.selectfield.SelectFieldGenerator.generateSelectField$$anonfun$adapted$2(SelectFieldGenerator.scala:26)

Best,
Romain

@kenbot
Copy link
Collaborator

kenbot commented Jul 16, 2021

Thanks for the report @romainreuillon! It looks like it shouldn't be too hard to track down. Interestingly, the pre-applied version works fine:

import monocle.Monocle._
cc.focus(_.i).get
// => 3

So it looks like the bit that is reading the explicitly supplied type is being a bit too literal when trying to discover the case class structure.

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

Successfully merging a pull request may close this issue.

2 participants