-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refine overloading and implicit disambiguation #20084
Refine overloading and implicit disambiguation #20084
Conversation
We sometimes have two alternatives a.m and b.m with the same symbol but different prefixes. Previously these would always be ambiguous. We now try to disambiguate this so that the alternative with the more specific prefix wins. To determine this, we widen prefixes also going from module classes to their parents and then compare the resulting types. This might fix a problem in ScalaTest that popped up after scala#20054.
compareOwner did certain tests for one side but not for the other, which made its outcome dependent on the order in which alternatives were presented.
The alternatives with the same symbol could have nevertheless different types. We first want to disambiguate based on these types before we turn to prefixes as a final tie breaker.
714c774
to
8eeee0b
Compare
It did not fix the ScalaTest problem but it's an improvement anyway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following example using an implicit parameter does not work as before
class I[X]
class J[X]
trait A:
given I[B] = ???
given (using I[B]): J[B] = ???
object A extends A
trait B extends A
object B extends B
//import B.given, A.given
def Test =
summon[I[B]]
summon[J[B]] // Error
I tried an alternative here using the prefix comparison in both cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest commit LGTM
Fix #21669 This part of code is from #20084 We should check `parents` is non-empty before calling `reduceLeft`. I haven't been able to create a standalone test. To test locally: `i21669.scala` ```scala //> using dep "com.softwaremill.sttp.tapir::tapir-sttp-client:1.11.5" import sttp.tapir.* import sttp.tapir.client.sttp.SttpClientInterpreter @main def run = lazy val pingGET = endpoint.get .in("ping") .out(stringBody) SttpClientInterpreter() .toRequest(pingGET, Some(uri"http://localhost:8080")) ``` ``` > sbt publishLocal > scala compile --server=false -S 3.6.0-RC1-bin-SNAPSHOT i21669.scala -- [E008] Not Found Error: /dotty/i21669.scala:12:33 ------ 12 | .toRequest(pingGET, Some(uri"http://localhost:8080")) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |value uri is not a member of StringContext, but could be made available as an extension method. | |One of the following imports might fix the problem: | | import sttp.client3.UriContext | import sttp.client3.quick.UriContext | import sttp.model.Uri.UriContext | 1 error found Compilation failed ```
We sometimes have two alternatives a.m and b.m with the same symbol and type but different prefixes. Previously these would always be ambiguous. We now try to disambiguate this so that the alternative with the more specific prefix wins. To determine this, we widen prefixes also going from module classes to their parents and then compare the resulting types.
This might fix a problem in ScalaTest that popped up after #20054.