Skip to content

Commit 5d4074f

Browse files
committed
Avoid ambiguity errors over Nothing
1 parent 8c6269d commit 5d4074f

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,14 @@ object Implicits:
492492
class AmbiguousImplicits(val alt1: SearchSuccess, val alt2: SearchSuccess, val expectedType: Type, val argument: Tree) extends SearchFailureType {
493493
def explanation(using Context): String =
494494
em"both ${err.refStr(alt1.ref)} and ${err.refStr(alt2.ref)} $qualify"
495-
override def whyNoConversion(using Context): String = {
496-
val what = if (expectedType.isInstanceOf[SelectionProto]) "extension methods" else "conversions"
497-
i"""
498-
|Note that implicit $what cannot be applied because they are ambiguous;
499-
|$explanation"""
500-
}
495+
override def whyNoConversion(using Context): String =
496+
if !argument.isEmpty && argument.tpe.widen.isRef(defn.NothingClass) then
497+
""
498+
else
499+
val what = if (expectedType.isInstanceOf[SelectionProto]) "extension methods" else "conversions"
500+
i"""
501+
|Note that implicit $what cannot be applied because they are ambiguous;
502+
|$explanation"""
501503
}
502504

503505
class MismatchedImplicit(ref: TermRef,

tests/neg/i8032.scheck

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i8032.scala:1:15 --------------------------------------------------------------
2+
1 |val x: 1 | 2 = 3 // error
3+
| ^
4+
| Found: (3 : Int)
5+
| Required: (1 : Int) | (2 : Int)
6+
-- [E008] Not Found Error: tests/neg/i8032.scala:3:12 ------------------------------------------------------------------
7+
3 |val y = ???.map // error
8+
| ^^^^^^^
9+
| value map is not a member of Nothing

0 commit comments

Comments
 (0)