Skip to content

Typer regression in contextual higher kinded types  #15171

Closed
@WojciechMazur

Description

@WojciechMazur

Compiler version

3.2.0-RC1-bin-20220429-400427d-NIGHTLY

Works with 3.1.2

First bad commit fe40c59 in #14840

Minimized code

Based on https://github.com/rssh/dotty-cps-async/blob/7563fc15c0de9efffee3d166d01f0e83d1d20433/shared/src/test/scala/cps/gopherlike/SLBase.scala#L136-L148

//> using scala "3.2.0-RC1-bin-20220429-400427d-NIGHTLY"
// //> using scala "3.1.2" // Last stable working version

case class Expr[+T](get: T)
trait Ctx[F[_]]
sealed trait Selector[F[_]]:
  def appended(base: Expr[SelectLoop[F]]): Expr[SelectLoop[F]]
  
 // Without Ctx[F] argument it would compile correctly
class SelectLoop[F[_]](using Ctx[F])
object SelectLoop:
  def loopImpl[F[_]](ctx: Ctx[F])(caseDefs: List[Selector[F]]): Expr[Unit] = 
    // Adding explicit type :Expr[SelectLoop[F]] satifies the compiler
    val s0 = Expr(new SelectLoop[F](using ctx)) 
    val g = caseDefs.foldRight(s0)(_.appended(_))
    Expr(())

Output

[error] ./test.scala:13:47: Found:    (_$6 : Expr[Object])
[error] Required: Expr[SelectLoop[F]]
[error] 
[error] where:    F is a type in method loopImpl with bounds <: [_] =>> Any
[error]     val g = caseDefs.foldRight(s0)(_.appended(_))
[error]                                               ^

Expectation

Should compile like in the 3.1.2, without need for explicit type annotation

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions