Skip to content

Commit 8156612

Browse files
committed
Fix #7813: Harden typedImplicit
1 parent dc6f51d commit 8156612

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,18 +1401,17 @@ trait Implicits { self: Typer =>
14011401
untpd.Apply(untpdConv, untpd.TypedSplice(argument) :: Nil),
14021402
pt, locked)
14031403
}
1404-
if (cand.isExtension) {
1405-
val SelectionProto(name: TermName, mbrType, _, _) = pt
1406-
val result = extMethodApply(untpd.Select(untpdGenerated, name), argument, mbrType)
1407-
if (!ctx.reporter.hasErrors && cand.isConversion) {
1408-
val testCtx = ctx.fresh.setExploreTyperState()
1409-
tryConversion(testCtx)
1410-
if (testCtx.reporter.hasErrors)
1411-
ctx.error(em"ambiguous implicit: $generated is eligible both as an implicit conversion and as an extension method container")
1412-
}
1413-
result
1414-
}
1415-
else tryConversion
1404+
pt match
1405+
case SelectionProto(name: TermName, mbrType, _, _) if cand.isExtension =>
1406+
val result = extMethodApply(untpd.Select(untpdGenerated, name), argument, mbrType)
1407+
if !ctx.reporter.hasErrors && cand.isConversion then
1408+
val testCtx = ctx.fresh.setExploreTyperState()
1409+
tryConversion(testCtx)
1410+
if testCtx.reporter.hasErrors then
1411+
ctx.error(em"ambiguous implicit: $generated is eligible both as an implicit conversion and as an extension method container")
1412+
result
1413+
case _ =>
1414+
tryConversion
14161415
}
14171416
if (ctx.reporter.hasErrors) {
14181417
ctx.reporter.removeBufferedMessages

tests/neg/i7813.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
implicit def f[X <: Undefined](implicit a: Int): X = ??? // error
2+
def g(arg: h.NonExistent): Int = ???
3+
val h: Int = ???

0 commit comments

Comments
 (0)