From 209b18ee59fbf4e7154576c00e3d678892849bf6 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 20 Dec 2021 18:29:56 +0100 Subject: [PATCH] Fix `derivedPolyProto` to use the correct result type The method parameter was called `resultType` but inside the method we use `resType` which is the result type of the existing PolyProto instance, so TypeMaps never updated the result type of a PolyProto before. According to git blame, this typo was introduced when the class parameter was renamed back in 2015 in b5c3a28f1eabada74827e34743dc264e583f7479. --- compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala | 2 +- tests/neg/i14145.scala | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i14145.scala diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 800af19e9f78..76fcb77d8c30 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -582,7 +582,7 @@ object ProtoTypes { override def isMatchedBy(tp: Type, keepConstraint: Boolean)(using Context): Boolean = canInstantiate(tp) || tp.member(nme.apply).hasAltWith(d => canInstantiate(d.info)) - def derivedPolyProto(targs: List[Tree], resultType: Type): PolyProto = + def derivedPolyProto(targs: List[Tree], resType: Type): PolyProto = if ((targs eq this.targs) && (resType eq this.resType)) this else PolyProto(targs, resType) diff --git a/tests/neg/i14145.scala b/tests/neg/i14145.scala new file mode 100644 index 000000000000..e9619ae9d756 --- /dev/null +++ b/tests/neg/i14145.scala @@ -0,0 +1,4 @@ +val l: List[Option[Int]] = List(None, Some(1), None) + +@main def m15 = + l.collectFirst(Some.unapply.unlift[Option[Int], Int]) // error