Skip to content

Better error message for errors arising from implicit completions #12002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3055,6 +3055,10 @@ class Typer extends Namer
case _ =>
EmptyTree

def nestedFailure(ex: TypeError) =
rememberSearchFailure(qual,
SearchFailure(qual.withType(NestedFailure(ex.toMessage, selectionProto))))

// try an extension method in scope
try
val nestedCtx = ctx.fresh.setNewTyperState()
Expand All @@ -3065,30 +3069,31 @@ class Typer extends Namer
for err <- nestedCtx.reporter.allErrors.take(1) do
rememberSearchFailure(qual,
SearchFailure(app.withType(FailedExtension(app, selectionProto, err.msg))))
catch case ex: TypeError =>
rememberSearchFailure(qual,
SearchFailure(qual.withType(NestedFailure(ex.toMessage, selectionProto))))
catch case ex: TypeError => nestedFailure(ex)

// try an implicit conversion or given extension
if ctx.mode.is(Mode.ImplicitsEnabled) && !tree.name.isConstructorName && qual.tpe.isValueType then
trace(i"try insert impl on qualifier $tree $pt") {
val selProto = selectionProto
inferView(qual, selProto) match
case SearchSuccess(found, _, _, isExtension) =>
if isExtension then return found
else
checkImplicitConversionUseOK(found)
return typedSelect(tree, pt, found)
case failure: SearchFailure =>
if failure.isAmbiguous then
return (
if canDefineFurther(qual.tpe.widen) then
tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, privateOK)
else
err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
)
rememberSearchFailure(qual, failure)
}
try
trace(i"try insert impl on qualifier $tree $pt") {
val selProto = selectionProto
inferView(qual, selProto) match
case SearchSuccess(found, _, _, isExtension) =>
if isExtension then return found
else
checkImplicitConversionUseOK(found)
return typedSelect(tree, pt, found)
case failure: SearchFailure =>
if failure.isAmbiguous then
return (
if canDefineFurther(qual.tpe.widen) then
tryExtensionOrConversion(tree, pt, mbrProto, qual, locked, compat, privateOK)
else
err.typeMismatch(qual, selProto, failure.reason) // TODO: report NotAMember instead, but need to be aware of failure
)
rememberSearchFailure(qual, failure)
}
catch case ex: TypeError => nestedFailure(ex)

EmptyTree
end tryExtensionOrConversion

Expand Down
14 changes: 14 additions & 0 deletions tests/neg/i11994.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- [E008] Not Found Error: tests/neg/i11994.scala:1:28 -----------------------------------------------------------------
1 |implicit def foo[T <: Tuple.meow]: Unit = ??? // error
| ^^^^^^^^^^
| type meow is not a member of object Tuple.
| Extension methods were tried, but the search failed with:
|
| Cyclic reference involving method foo
-- [E008] Not Found Error: tests/neg/i11994.scala:2:18 -----------------------------------------------------------------
2 |given [T <: Tuple.meow]: Unit = ??? // error
| ^^^^^^^^^^
| type meow is not a member of object Tuple.
| Extension methods were tried, but the search failed with:
|
| Cyclic reference involving method given_Unit
2 changes: 2 additions & 0 deletions tests/neg/i11994.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
implicit def foo[T <: Tuple.meow]: Unit = ??? // error
given [T <: Tuple.meow]: Unit = ??? // error
6 changes: 6 additions & 0 deletions tests/pos/i11994.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class WeirdNumber(v: Double) extends java.lang.Number {
override def doubleValue = v
override def intValue = v.intValue
override def longValue = v.longValue
override def floatValue = v.floatValue
}