-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Compile failure with right associative op and conversion #15939
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
It has nothing to do with right associativity. The following also fails: mport scala.language.implicitConversions
object Test {
class Foo {
class Bar {
override def toString() = "bar"
}
object Bar {
implicit def fromString(a: String): Bar = { println("convert bar") ; new Bar }
}
def andThen(b: Bar): Unit = { println("pre") ; println(s"use $b") ; println("post") }
}
def mkFoo: Foo = ???
def mkBarString: String = ???
mkFoo.andThen(mkBarString)
} However, if I change the What goes on here: The compiler needs to find a type for -- [E007] Type Mismatch Error: test.scala:17:16 --------------------------------
17 | mkFoo.andThen(mkBarString)
| ^^^^^^^^^^^
| Found: String
| Required: ?9.Bar
|
| where: ?9 is an unknown value of type Test.Foo
| I don't think there's anything that can be done here except improve the error diagnostics, but even that is a huge problem since the logic that causes this is very far away from where we assemble error messages. |
I believe the conclusion is that implicit conversions are a bad idea and implicit conversions in nested classes inside other classes are an even worse idea. Maybe we should outlaw implicit conversions? |
Indeed, the test is also to show order of operations when conversions are involved. Lukas's observation was that there is no correct answer. But other implicit lookups besides conversions may be required; I'll check those use cases. |
The previous scheme did not set the approximated flag in some cases, which led to the appearance of unhelpful Nothing types in error messages. We now always mark the AsSeenFrom map as approximated when encountering an illegal prefix at variance <= 0. But we reset it again when a range in a prefix is dropped because we can follow a type alias or use a singleton type info. Furthermore, we use an `Int`, `approxCount` instead of `approximated` to keep track of multiple approximation points. Fixes #15939 in the sense that the error message now makes more sense. We still cannot find the implicit conversion; that would require a more global measure to fix the problem (such as going to ANF) or existential types.
Compiler version
Scala compiler version 3.1.3 -- Copyright 2002-2022, LAMP/EPFL
Scala compiler version 3.2.1-RC1-bin-SNAPSHOT-git-456444b -- Copyright 2002-2022, LAMP/EPFL
Minimized code
Output
From
-Vprint:typer
Expectation
Successful compilation of Scala 2 test
test/files/run/t4225e.scala
The text was updated successfully, but these errors were encountered: