scala / scala3

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

Context function typecheck failure #21136

Open Bersier opened 2 months ago

Bersier commented 2 months ago

Compiler version

3.5.0-RC3

Minimized code

def foo1: Any =
  val env = Env("a", false)
  Let(env, Var("a"))

def foo2: Any =
  // When env is inlined, compilation fails.
  Let(Env("a", false), Var("a"))

class Let[T](val varDefs: Env[?], val body: EnvGiven[varDefs.type] ?=> Var[?, T])

case class Var[Name <: Singleton, T](name: Name)(using VarGiven[Name])

case class Env[Name <: Singleton](name: Name, t: Any)

// Compilation also fails when E is not marked as covariant.
trait EnvGiven[+E <: Env[?]]

trait VarGiven[Name]
given head[Name <: Singleton](using EnvGiven[Env[Name]]): VarGiven[Name]()

Output

Found:    (EnvGiven[(?1 : Env[("a" : String)])]) ?=> Var[?, T]
Required: (EnvGiven[(?2 : Env[("a" : String)])]) ?=> Var[?, T]

where:    ?1 is an unknown value of type Env[("a" : String)]
          ?2 is an unknown value of type Env[("a" : String)]
          T  is a type variable

Expectation

No compile-error

Bersier commented 2 months ago

@Gedochao I don't think it is related to inline (my comment is about manually inlining an expression).