Skip to content

Incorrect type selection due to mixin #16133

@Bersier

Description

@Bersier

Compiler version

3.2.0

Minimized code

sealed trait NatT
final case class Zero() extends NatT
final case class Succ[N <: NatT](n: N) extends NatT

type _0 = Zero
type _1 = Succ[_0]

given Zero = Zero()
given [N <: NatT](using n: N): Succ[N] = Succ(n)
// a variant for the previous line leading to a different error message: 
// given Succ[Zero] = Succ(Zero())

trait Mixin

class Instance[N <: NatT](using N)

trait Container[N <: NatT]:
  def instance: Instance[N]

class Refined extends Container[_1]:
  def instance: Instance[_1] & Mixin = new Instance() with Mixin

Compiler output

Found:    Instance[Zero] with Mixin {...}
Required: Instance[_1] & Mixin

Expectation

No compiler error.

The code does compile when the last line is changed to

  def instance: Instance[_1] & Mixin = new Instance[_1]() with Mixin

or when there is no mixin.

For more complex code, I've seen errors due to this that are impossible to decipher, as they wrongly assert that other using parameters are missing. Unfortunately, they are hard to reproduce with a small piece of code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions