Skip to content

Incremental compilation and opaque types don't play nice together #13190

Closed
@Katrix

Description

@Katrix

Compiler version

3.0.1

Minimized code

fileA.scala

object Opaque {
  opaque type FieldType[K, +V] <: V = V
}

fileB.scala

import Opaque.*

object Test {
  type FindField[R <: scala.Tuple, K] = R match {
    case FieldType[K, f] *: t => f
    case _ *: t => FindField[t, K]
  }

  val f: FieldType["A", Int] = ???
  val f1: Int = f
  //val f2: Int = f

  type R = FieldType["A", Int] *: FieldType["B", Double] *: FieldType["C", String] *: FieldType["D", Boolean] *: EmptyTuple
  summon[FindField[R, "B"] =:= Double]
}

Steps to reproduce

  1. Compile both files together in a project. Everything should compile fine.
  2. Uncomment val f2: Int = f
  3. Try to compile again (and not cleaning beforehand). It will error for f1, f2, and the summon
  4. Clean and compile. It works again

Output

[error] -- [E007] Type Mismatch Error: D:\DevProjects\Stable\shapeless\core\src\main\scala-3\fileB.scala:10:16
[error] 10 |  val f1: Int = f
[error]    |                ^
[error]    |              Found:    (Test.f : Opaque.FieldType[("A" : String), Int])
[error]    |              Required: Int
[error] -- [E007] Type Mismatch Error: D:\DevProjects\Stable\shapeless\core\src\main\scala-3\fileB.scala:11:16
[error] 11 |  val f2: Int = f
[error]    |                ^
[error]    |              Found:    (Test.f : Opaque.FieldType[("A" : String), Int])
[error]    |              Required: Int
[error] -- Error: D:\DevProjects\Stable\shapeless\core\src\main\scala-3\fileB.scala:14:38
[error] 14 |  summon[FindField[R, "B"] =:= Double]
[error]    |                                      ^
[error]    |Cannot prove that Test.FindField[Test.R, ("B" : String)] =:= Double.
[error]    |
[error]    |One of the following imports might make progress towards fixing the problem:
[error]    |
[error]    |  import shapeless.~?>.idKeyWitness
[error]    |  import shapeless.~?>.idValueWitness
[error]    |  import shapeless.~?>.witness
[error]    |
[error]    |
[error]    |
[error]    |Note: a match type could not be fully reduced:
[error]    |
[error]    |  trying to reduce  Test.FindField[Test.R, ("B" : String)]
[error]    |  failed since selector  Test.R
[error]    |  does not match  case Opaque.FieldType[("B" : String), f] *: t => f
[error]    |  and cannot be shown to be disjoint from it either.
[error]    |  Therefore, reduction cannot advance to the remaining case
[error]    |
[error]    |    case _ *: t => Test.FindField[t, ("B" : String)]

Expectation

It should compile in both cases, also when using incremental compilation.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions