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 Mismatch Error for the same type #26

Closed
LightSystem opened this issue Jan 4, 2023 · 3 comments · Fixed by #27
Closed

Type Mismatch Error for the same type #26

LightSystem opened this issue Jan 4, 2023 · 3 comments · Fixed by #27

Comments

@LightSystem
Copy link

LightSystem commented Jan 4, 2023

Hi @arainko,
First of all thank you for this awesome library! It is a godsend that is helping us migrate to Scala 3 in a more painless manner 😌

I've just started using it for some of our case class transformations and have encountered a curious issue. Seems to have to do with companion objects or objects in general.
Let's imagine I have these case classes:

case class A(anotherCaseClass: AnotherCaseClass)
object A:
  case class AnotherCaseClass(name: String)
  case class B(anotherCaseClass: AnotherCaseClass)

AnotherCaseClass can be simple or complex, it doesn't matter. If I then do:

val a = A(AnotherCaseClass("test"))
a.to[B]

I get the following compilation error:

[error] -- [E007] Type Mismatch Error: /some/file:95:11 
[error] 95 |    a.to[B]
[error]    |           ^
[error]    |           Found:    A.AnotherCaseClass | dest
[error]    |           Required: A.AnotherCaseClass
[error]    |----------------------------------------------------------------------------
[error]    |Inline stack trace
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from LiftTransformationModule.scala:15
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from LiftTransformationModule.scala:15
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    |This location contains code that was inlined from LiftTransformationModule.scala:15

I'm using scala 3.2.1 and ducktape version 0.1.1.

Thanks again. If I get some time I'll try to research this problem deeper by looking into ducktape's codebase though metaprogramming is something I'm not very familiar with yet.

@arainko
Copy link
Owner

arainko commented Jan 5, 2023

Hey @LightSystem! Thanks for reporting the issue and sorry for the inconvenience that it causes!

I can reproduce it locally and will be taking a closer look at it in the following days. The issue seems to stem from the placement of the case class in the companion object, just as you said.

In the meantime a workaround (you probably figured it out already but I'm putting it out there in case someone also stumbles upon this) is to move out the definition of AnotherCaseClass out of the companion object of A, so the code would look like this:

case class A(anotherCaseClass: AnotherCaseClass)
case class AnotherCaseClass(name: String)

object A:
  case class B(anotherCaseClass: AnotherCaseClass)

@arainko
Copy link
Owner

arainko commented Jan 5, 2023

Some further findings:

It turns out that if you refer to SomeOtherClass as A.SomeOtherClass in B, like this:

case class A(anotherCaseClass: A.AnotherCaseClass)

object A {
  case class AnotherCaseClass(name: String)
  case class B(anotherCaseClass: A.AnotherCaseClass)
}

it's all fine and dandy, but once you get rid of the A. prefix in B it goes back to being broken. Feels like I'm taking crazy pills.

So that'd make it the go-to workaround for this issue for now - I'm investigating further 😸

arainko added a commit that referenced this issue Jan 7, 2023
* reproduce issue 26

* workaround by prefixing `AnotherCaseClass` with `A.`

* fix issue 26
@arainko
Copy link
Owner

arainko commented Jan 7, 2023

Managed to pinpoint the cause and resolve the issue, more details in #27. ducktape 0.1.2 with the fix applied is on its way to Maven Central. Once again thanks for using the library and reporting the issue @LightSystem!

arainko added a commit that referenced this issue Jan 8, 2023
* reproduce issue 26

* workaround by prefixing `AnotherCaseClass` with `A.`

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

Successfully merging a pull request may close this issue.

2 participants