Skip to content

Failing to infer type of based on type member refinement of type parameter #12797

Open
@eejbyfeldt

Description

@eejbyfeldt

Reproduction steps

Scala version: 2.13 and 2.12 but works in scala 3

trait Base {
  type M
}

final class Impl extends Base {
  type M = Int
}

object Test {
  def toRep[T, S <: Base { type M = T }](s: S): T = ???

  toRep(new Impl)
}

Problem

Trying to compile the code above it fails with

refinement_inference.scala:12: error: inferred type arguments [Nothing,Impl] do not conform to method toRep's type parameter bounds [T,S <: Base{type M = T}]
  toRep(new Impl)
  ^
refinement_inference.scala:12: error: type mismatch;
 found   : Impl
 required: S
  toRep(new Impl)
        ^
two errors found

so the compiler failed to infer the type of T correctly.

More info

Changing the def of toRep slightly so

def toRep[T, S <: Base](s: S { type M = T }): T = ???

makes it infer the correct type and the code compiles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)typer

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions