Skip to content

Type inferer fails to unify a member type between different, structurally identical refinements on that type #12448

@noresttherein

Description

@noresttherein

reproduction steps

using Scala 2.13.6,

	trait iType {
		type Bug
	}
	type iGood[X] = iType { type Bug = X }
	type iBug[X] = iType { type Bug = X }

	class Box[X]
	def Box[X](bug :iBug[X]) :Box[X] = ???

	trait Super {
		def apply[X](arg :iGood[X]) :Box[X]
	}

	class Impl extends Super {
		override def apply[X](arg :iGood[X]) = Box(arg)
	}

problem

ncompatible type in overriding
def apply[X](arg: Playground.iGood[X]): Playground.Box[X] (defined in trait Super);
 found   : [X(in method apply)](arg: Playground.iGood[X(in method apply)]): Playground.Box[this.Bug]
    (which expands to)  [X(in method apply)](arg: Playground.iType{type Bug = X(in method apply)}): Playground.Box[X]
 required: [X(in method apply)](arg: Playground.iGood[X(in method apply)]): Playground.Box[X(in method apply)]
    (which expands to)  [X(in method apply)](arg: Playground.iType{type Bug = X(in method apply)}): Playground.Box[X(in method apply)]
		override def apply[X](arg :iGood[X]) = Box(arg)

The crucial part to the reproduction is that the type argumet of the returned Box is inferred based on an argument of a different type alias than its formal parameter (iGood vs. iBug). Switching from iBug to iGood makes it work and so does explicitly specifying the return type as Box[S].

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