Iltotore / iron

Strong type constraints for Scala
https://iltotore.github.io/iron/docs/
Apache License 2.0
430 stars 38 forks source link

Compiler crash on v2.3.0: cannot resolve reference toRefinedTypeOps.type.Mirror #190

Closed jnicoulaud-ledger closed 8 months ago

jnicoulaud-ledger commented 8 months ago

Describe the bug Scala environment: JVM Scala version: 3.3.0 Iron version: 2.3.0

Reproduction steps The steps to reproduce the described issue

Expected behavior Compilation successful

Current behavior Compilation fails with error:

dotty.tools.FatalError: cannot resolve reference to type io.github.iltotore.iron.RefinedTypeOps$package.RefinedTypeOps.type.Mirror
the classfile defining the type might be missing from the classpath while running MegaPhase{elimErasedValueType, pureStats, vcElideAllocations, etaReduce, arrayApply, elimPolyFunction, tailrec, completeJavaEnums, mixin, lazyVals, memoize, nonLocalReturns, capturedVars} on /runner/_work/cloud-sync-backend/cloud-sync-backend/modules/api/src/main/scala/co/ledger/cloud_sync/api/sync/package.scala
[error] cannot resolve reference to type io.github.iltotore.iron.RefinedTypeOps$package.RefinedTypeOps.type.Mirror
[error] the classfile defining the type might be missing from the classpath
Iltotore commented 8 months ago

Sometimes, name changes like this mess up with incremental compilation. Did you try to clean the compiler cache?

jnicoulaud-ledger commented 8 months ago

Yes, it was a clean build. Also tried removing wartremover, scalafix and upgrading to scala 3.3.1 with same result. I will try to reduce my project to the bare minimum...

Iltotore commented 8 months ago

It would also be useful to know where the compiler produces this error. Does it occur when compiling the file containing your new types or when compiling a file using them?

jnicoulaud-ledger commented 8 months ago

I created a minimal reproducing project here: https://github.com/jnicoulaud-ledger/iron-issue-190-reproducer You can see the compiler crash in the CI: https://github.com/jnicoulaud-ledger/iron-issue-190-reproducer/actions/runs/6754239254/job/18361529999#step:4:32 (gave you push access to this repo if you want to experiment)

edit: well basically, this compiles on iron 2.2.1:

import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.numeric.*
import sttp.tapir.Codec.PlainCodec
import sttp.tapir.codec.iron.TapirCodecIron

opaque type Version = Int :| GreaterEqual[0]

object Version extends RefinedTypeOpsImpl[Int, GreaterEqual[0], Version] with TapirCodecIron:
  given PlainCodec[Version] = ironTypeCodec

this crashes on iron 2.3.0:

import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.numeric.*
import sttp.tapir.Codec.PlainCodec
import sttp.tapir.codec.iron.TapirCodecIron

opaque type Version = Int :| GreaterEqual[0]

object Version extends RefinedTypeOps[Int, GreaterEqual[0], Version] with TapirCodecIron:
  given PlainCodec[Version] = ironTypeCodec
Iltotore commented 8 months ago

This compiles: https://github.com/jnicoulaud-ledger/iron-issue-190-reproducer/tree/fix/issue-190

The Tapir's Iron integration probably just needs to be updated.

Iltotore commented 8 months ago

This PR should solve this issue once merged: https://github.com/softwaremill/tapir/pull/3298

For the time being, you can use the code I pushed on https://github.com/jnicoulaud-ledger/iron-issue-190-reproducer/tree/fix/issue-190

jnicoulaud-ledger commented 8 months ago

I could have thought of that :facepalm: thank you :)

Iltotore commented 8 months ago

The PR got merged. Feel free to open a new issue if the problem is still present.

Note that you will probably need to wait for Tapir to release a new version.