Skip to content

Commit 6f9d50c

Browse files
committed
Prefer method over poly when merging denotations
1 parent 4576865 commit 6f9d50c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,26 @@ object Denotations {
310310
}
311311
case tp1: MethodOrPoly =>
312312
tp2 match {
313-
case tp2: MethodOrPoly
314-
if ctx.typeComparer.matchingParams(tp1, tp2) &&
315-
tp1.isImplicit == tp2.isImplicit =>
316-
tp1.derivedLambdaType(
317-
mergeParamNames(tp1, tp2), tp1.paramInfos,
318-
infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
313+
case tp2: MethodOrPoly =>
314+
// Two remedial strategies
315+
// 1. Prefer method types over poly types. This is necessary to handle
316+
// overloaded definitions like the following
317+
//
318+
// def ++ [B >: A](xs: C[B]): D[B]
319+
// def ++ (xs: C[A]): D[A]
320+
//
321+
// (Code like this is found in the collection strawman)
322+
// 2. In the case of two method types or two polytypes with matching
323+
// parameters and implicit status, merge corresppnding parameter
324+
// and result types.
325+
if (tp1.isInstanceOf[PolyType] && tp2.isInstanceOf[MethodType]) tp2
326+
else if (tp2.isInstanceOf[PolyType] && tp1.isInstanceOf[MethodType]) tp1
327+
else if (ctx.typeComparer.matchingParams(tp1, tp2) &&
328+
tp1.isImplicit == tp2.isImplicit)
329+
tp1.derivedLambdaType(
330+
mergeParamNames(tp1, tp2), tp1.paramInfos,
331+
infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
332+
else mergeConflict(tp1, tp2)
319333
case _ =>
320334
mergeConflict(tp1, tp2)
321335
}

0 commit comments

Comments
 (0)