Skip to content

Commit b2e62b6

Browse files
committed
Better error message for errors arising from implicit completions
Fixes #11994
1 parent f01c14d commit b2e62b6

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,30 +3065,30 @@ class Typer extends Namer
30653065
for err <- nestedCtx.reporter.allErrors.take(1) do
30663066
rememberSearchFailure(qual,
30673067
SearchFailure(app.withType(FailedExtension(app, selectionProto, err.msg))))
3068+
3069+
// try an implicit conversion or given extension
3070+
if ctx.mode.is(Mode.ImplicitsEnabled) && !tree.name.isConstructorName && qual.tpe.isValueType then
3071+
trace(i"try insert impl on qualifier $tree $pt") {
3072+
val selProto = selectionProto
3073+
inferView(qual, selProto) match
3074+
case SearchSuccess(found, _, _, isExtension) =>
3075+
if isExtension then return found
3076+
else
3077+
checkImplicitConversionUseOK(found)
3078+
return typedSelect(tree, pt, found)
3079+
case failure: SearchFailure =>
3080+
if failure.isAmbiguous then
3081+
return (
3082+
if canDefineFurther(qual.tpe.widen) then
3083+
tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, privateOK)
3084+
else
3085+
err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
3086+
)
3087+
rememberSearchFailure(qual, failure)
3088+
}
30683089
catch case ex: TypeError =>
30693090
rememberSearchFailure(qual,
30703091
SearchFailure(qual.withType(NestedFailure(ex.toMessage, selectionProto))))
3071-
3072-
// try an implicit conversion or given extension
3073-
if ctx.mode.is(Mode.ImplicitsEnabled) && !tree.name.isConstructorName && qual.tpe.isValueType then
3074-
trace(i"try insert impl on qualifier $tree $pt") {
3075-
val selProto = selectionProto
3076-
inferView(qual, selProto) match
3077-
case SearchSuccess(found, _, _, isExtension) =>
3078-
if isExtension then return found
3079-
else
3080-
checkImplicitConversionUseOK(found)
3081-
return typedSelect(tree, pt, found)
3082-
case failure: SearchFailure =>
3083-
if failure.isAmbiguous then
3084-
return (
3085-
if canDefineFurther(qual.tpe.widen) then
3086-
tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, privateOK)
3087-
else
3088-
err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
3089-
)
3090-
rememberSearchFailure(qual, failure)
3091-
}
30923092
EmptyTree
30933093
end tryExtensionOrConversion
30943094

tests/neg/i11994.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E008] Not Found Error: tests/neg/i11994.scala:1:28 -----------------------------------------------------------------
2+
1 |implicit def foo[T <: Tuple.meow]: Unit = ??? // error
3+
| ^^^^^^^^^^
4+
| type meow is not a member of object Tuple.
5+
| Extension methods were tried, but the search failed with:
6+
|
7+
| Cyclic reference involving method foo
8+
-- [E008] Not Found Error: tests/neg/i11994.scala:2:18 -----------------------------------------------------------------
9+
2 |given [T <: Tuple.meow]: Unit = ??? // error
10+
| ^^^^^^^^^^
11+
| type meow is not a member of object Tuple.
12+
| Extension methods were tried, but the search failed with:
13+
|
14+
| Cyclic reference involving method given_Unit

tests/neg/i11994.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
implicit def foo[T <: Tuple.meow]: Unit = ??? // error
2+
given [T <: Tuple.meow]: Unit = ??? // error

0 commit comments

Comments
 (0)