-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Unapplicable implicit conversion in scope incorrectly masks applicable implicit conversion in outer scope. #13900
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
Comments
Can we identify the commit that broke this? |
Looks to me like a reasonable spree ticket, if anyone is interested in an investigative task. |
Minimized to: opaque type Inlined[T] = T
object Inlined:
given fromValueWide[Wide]: Conversion[Wide, Inlined[Wide]] = ???
def myMax: Int = 1 max 2 |
it looks like we apply many times |
I run git bisect between 3.1.1 and current master(0b4e96c) and the first commit which breaks it is 0182e06 which clearly states at the end of commit message:
So, it is unclear for me what should the next step be. Should we detect such cases and fail fast? |
Implicit conversions should never be chained, this is probably an underlying bug which was exposed by 0182e06 but is otherwise unrelated to it. opaque type Inlined[T] = T
object Inlined:
implicit def fromValueWide[Wide](x: Wide): Inlined[Wide] = ???
def myMax: Int = 1 max 2 Dumping the stack while the compiler is running reveals the loop (I didn't check how we break out of it): at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:616)
at dotty.tools.dotc.typer.Typer.tryExtensionOrConversion(Typer.scala:3274)
at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:619)
at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:616)
at dotty.tools.dotc.typer.Typer.tryExtensionOrConversion(Typer.scala:3274)
at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:619)
at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:616) I tried turning off recursive implicit searches in this codepath: diff --git compiler/src/dotty/tools/dotc/typer/Typer.scala compiler/src/dotty/tools/dotc/typer/Typer.scala
index d092568fc06..0f847a9b623 100644
--- compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -3270,7 +3270,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if isExtension then return found
else
checkImplicitConversionUseOK(found)
- return typedSelect(tree, pt, found)
+ return withoutMode(Mode.ImplicitsEnabled)(typedSelect(tree, pt, found))
case failure: SearchFailure =>
if failure.isAmbiguous then
return With that change, the original example compiles after adding an explicit result type to -- [E008] Not Found Error: tests/neg/i13900.scala:9:21 -------------------------
9 | def myMax: Int = 1 max 2
| ^^^^^
|value max is not a member of Inlined[Int], but could be made available as an extension method. Which is weird, since there's no member max in Inlined[Int] (which is equal to Int), we should just disregard it in the implicit search and it shouldn't fail. The check for the presence of max in the type we're converting to is done using Of course the implicit conversion doesn't really have unknown members: since it's lower-bounded by |
Just like in tryInsertImplicitOnQualifier, we need to turn off implicit search when typing a selection after instert an implicit conversion on the qualifier in tryExtensionOrConversion. Partially fixes scala#13900, see tests/neg/i13900.scala.
Just like in tryInsertImplicitOnQualifier, we need to turn off implicit search when typing a selection after instert an implicit conversion on the qualifier in tryExtensionOrConversion. Partially fixes scala#13900, see tests/neg/i13900.scala.
Just like in tryInsertImplicitOnQualifier, we need to turn off implicit search when typing a selection after instert an implicit conversion on the qualifier in tryExtensionOrConversion. Partially fixes scala#13900, see test case.
Just like in tryInsertImplicitOnQualifier, we need to turn off implicit search when typing a selection after inserting an implicit conversion on the qualifier in tryExtensionOrConversion. Partially fixes scala#13900, see test case.
I've opened #14750 to at least fix the loop. |
Re-opening to keep track of the error in https://github.com/lampepfl/dotty/blob/main/tests/neg/i13900.scala. |
As observed in scala#13900, hasKnownMembers gives problematic false positives. What we are really after is a (nontrivial) upper approximation of known members. Even uninstantiated type variables have such an approximation if their lower bound is defined and different from Nothing. Fixes scala#13900
EDIT: This no longer loops but emits an error when it shouldn't, see discussion starting at #13900 (comment)
Originally posted by @soronpo in #13878 (comment)
Minimized code:
https://scastie.scala-lang.org/5GNoOjh1SwSUuVMBTzRqFA
The code works in 3.1.1-RC1, but fails on master.
The workaround was to change the last line to
forced[Max[T, R]](math.max(lhs.value, rhs.value))
The text was updated successfully, but these errors were encountered: