scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.87k stars 1.06k forks source link

Compilation success depends on presence of irrelevant code #15740

Open rskfocus opened 2 years ago

rskfocus commented 2 years ago

Compiler version

3.1.3

Minimized code

f.scala:

package f

type R
type I >: R

sealed trait F[+R, +A]
object F {
  def p[A](x: A): F[Nothing, A] = ???

  def r[E : T](e: E): F[R, Nothing] = ???

  /* this method is never used, but affects compilation
   * the code compiles without it!
   */
  def unused[A](f: A): F[I, A] = F.r(1)
}

val _ = (x: F[I, Unit])

p.scala:

package f

val x: F[I, Unit] = F.p(())

T.scala:

package f

import scala.quoted._

class T[X]

object T {
  inline given derivedT[X]: T[X] = ${ derivedTImpl[X] }

  def derivedTImpl[X](using t: Type[X])(using ctx: Quotes): Expr[T[X]] = {
    '{ new T }
  }
}

Output

[error] -- [E007] Type Mismatch Error: /home/<redacted>/f.scala:18:9 
[error] 18 |val _ = (x: F[I, Unit])
[error]    |         ^
[error]    | Found:    (f.x : f.F[f.I, Unit])
[error]    | Required: f.F[f.I², Unit]
[error]    |
[error]    | where:    I  is a type in package object f$package with bounds >: f.R
[error]    |           I² is a type in package object f$package with bounds >: f.R

Expectation

Code compiles. Note that this error appears only on clean; compile - second compile seems to succeed. Removal of some (seemingly unrelated) code also fixes the issue.

szymon-rd commented 2 years ago

Removing incremental compilation tag as it also occurs after clean; build.