-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Compiler error caused by import of unrelated extension #13558
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 would be nice if this worked, but it does not work this way.
Crucially, two subsequent imports do not created an overloaded reference. They are simply ambiguous. The only thing to do here is to improve the error message so that the ambiguity gets mentioned. |
The problem is that this limitation piles on yet-another-thing-that-implicit-classes-can-do-and-extension-methods-can't. class A
class B
object ExtensionA {
implicit class ICA(self: A) {
def id = "A"
}
}
object ExtensionB {
implicit class ICB(self: B) {
def id = "B"
}
}
object Main {
def main(args: Array[String]): Unit = {
import ExtensionA._
import ExtensionB._
val a = A()
println(a.id)
}
} |
The workaround for this limitation is to use class A
class B
object ExtensionA {
extension (self: A) {
def id = "A"
}
}
object ExtensionB {
extension (self: B) {
def id = "B"
}
}
object ExtensionAB{
export ExtensionA._
export ExtensionB._
}
object Main {
def main(args: Array[String]): Unit = {
import ExtensionAB._
val a = A()
println(a.id)
val b = B()
println(b.id)
}
} |
Compiler version
3.0.2
Minimized code
Output
Expectation
It should not ambiguous which extension to use and therefore the ExtensionB import should not matter.
The text was updated successfully, but these errors were encountered: