diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 6a033282fbff..c1c0332db8a2 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -710,7 +710,11 @@ object ProtoTypes { override def eql(that: Type): Boolean = that match case that: ViewProto => (argType eq that.argType) && (resType eq that.resType) case _ => false + // equals comes from case class; no need to redefine + + override def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T = + ta(x, argType) } object ViewProto { diff --git a/tests/neg/17305.check b/tests/neg/17305.check new file mode 100644 index 000000000000..5111bb69fe40 --- /dev/null +++ b/tests/neg/17305.check @@ -0,0 +1,7 @@ +-- [E007] Type Mismatch Error: tests/neg/17305.scala:15:47 ------------------------------------------------------------- +15 | .use((pair) => myAssert(pair)(someAssertion(2))) // error + | ^^^^^^^^^^^^^^^^ + | Found: Assertion[Int] + | Required: Assertion[Long] + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/17305.scala b/tests/neg/17305.scala new file mode 100644 index 000000000000..bd06afb862fa --- /dev/null +++ b/tests/neg/17305.scala @@ -0,0 +1,37 @@ +trait Wrapper[A1] { + def use(a: A1 => Unit): Unit +} + +trait Assertion[A2] {} + +def hideTypeInOut[A3]( + c1: A3 + )(using + hider: HideAInOut[A3] +): Wrapper[hider.Out] = ??? + +def entryPoint(): Unit = { + hideTypeInOut(1L) + .use((pair) => myAssert(pair)(someAssertion(2))) // error +} + +private def myAssert[A4](a: A4)(assertion: Assertion[A4]): Unit = () + +// This should be Unit or generic, but let compiler figure it out +private def someAssertion(i: Int): Assertion[Int] = ??? + +trait HideAInOut[-A] { + type Out + def get(left: A): Out +} + +object HideAInOut { + + type Out[HideA, HideB] = HideAInOut[HideA] { type Out = HideB } + + given [ImplicitA]: HideAInOut.Out[ImplicitA, ImplicitA] = + new HideAInOut[ImplicitA] { + type Out = ImplicitA + def get(left: ImplicitA): Out = left + } +}