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
Make Scala-3-style implicit resolution explicitly opt-in rather than bundled in -Xsource:3
#10012
Conversation
I would be in favor of having it be false under -Xsource:3 by default too, better to not enable something we know is broken. |
I agree. A little history on this: at the time these changes were added to Over time, this has shifted and (And besides, it took time for scala/bug#12437 to come to light; but now we know.) I'd like to know what @lrytz thinks, though. |
Thx for taking a look. I made a change to not enable I'll squash the commits when the final decision about that is made. |
24c91fa
to
3570c0f
Compare
Maybe that test depends on the Java version? Not sure...
SGTM 👍 It's probably worth keeping the ticket open, or creating a new one, as the issue is not fixed. |
I'll remove "Fixes" from the commit message so that the issue doesn't get auto-closed. |
@lrytz @SethTisue @smarter good to merge? :] |
@@ -283,6 +283,7 @@ trait ScalaSettings extends StandardScalaSettings with Warnings { _: MutableSett | |||
val YpickleWrite = StringSetting("-Ypickle-write", "directory|jar", "destination for generated .sig files containing type signatures.", "", None).internalOnly() | |||
val YpickleWriteApiOnly = BooleanSetting("-Ypickle-write-api-only", "Exclude private members (other than those material to subclass compilation, such as private trait vals) from generated .sig files containing type signatures.").internalOnly() | |||
val YtrackDependencies = BooleanSetting("-Ytrack-dependencies", "Record references to in unit.depends. Deprecated feature that supports SBT 0.13 with incOptions.withNameHashing(false) only.", default = true) | |||
val Yscala3ImplicitResolution = BooleanSetting("-Yscala3-implicit-resolution", "Use Scala-3-style downwards comparisons for implicit search and overloading resolution", default = false) |
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.
Maybe add a link to scala/bug#12437 in the description
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.
Will do 👍
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.
I've made a change like this: 8bb6e43#diff-87059578fba24c0fb0b0fcca877242dff060ac85c89dbf2dfd04548d477f8e6bR278
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.
2.13.9 is close so I hope we can get this merged before the release, I just had one comment (https://github.com/scala/scala/pull/10012/files#r858043339) but it shouldn't block us from merging this.
@povder Could you attempt to revise the PR description to be what we call "user-facing", that is, to be maximally digestible even by an end user who has little/no understanding of the history here? It's most important to be clear about 1) the motivation for the change, 2) what users should do (and which users need to do anything at all). |
-Xsource:3
@milessabin would you like to review this? |
Will do today 👍 |
@SethTisue I've changed the description of this PR in an attempt to address your comment. |
Perfect! |
@@ -1168,6 +1168,7 @@ class Global(var currentSettings: Settings, reporter0: Reporter) | |||
|
|||
// We hit these checks regularly. They shouldn't change inside the same run, so cache the comparisons here. | |||
val isScala3 = settings.isScala3 | |||
val isScala3ImplicitResolution = settings.Yscala3ImplicitResolution |
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.
This is a BooleanSetting
, not a Boolean
.
case _ if !currentRun.isScala3 => existentialAbstraction(undef1, tpe1) <:< existentialAbstraction(undef2, tpe2) | ||
case _ => | ||
case PolyType(tparams2, rtpe2) => isAsSpecificValueType(tpe1, rtpe2, undef1, undef2 ::: tparams2) | ||
case _ if !currentRun.isScala3ImplicitResolution => existentialAbstraction(undef1, tpe1) <:< existentialAbstraction(undef2, tpe2) |
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.
This incurs the implicit conversion. I wonder why I don't see a warning currently. Edit: I catch this in that PR.
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.
I saw your comment and I was going to quickly make a change to avoid the conversion but upon checking out the most recent code I realized the conversion doesn't happen anymore with your change 0d252f6#diff-7b7600384a160cb93e5eceff814f6aed9f5c7b72b752a18c3f61d895482e75fcR907
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.
Thanks for checking my check. (That's what I meant by I caught it in my PR, which was about the same time as yours.) I might change them to vars, except there were a lot of isScala3
calls, so removing the .value
is not appealing. But that is why sed
is the "scala editor".
Motivation
Using
-Xsource:3
to enable some Scala 3 syntax and behavior breaks implicit resolution in certain cases, as described in bug report scala/bug#12437. Most notably it makes Scala.js unions not work. This PR disables Scala-3-style implicit resolution when-Xsource:3
is used (because it is currently broken) while making it possible to opt in to use it with a newly introduced flag-Yscala3-implicit-resolution
.Usage
If you use
-Xsource:3
and are impacted by scala/bug#12437 then do not add-Yscala3-implicit-resolution
to the Scala compiler options. It will disable Scala-3-style implicit resolution while still preserving other Scala 3 behavior in your Scala 2 code.If you use
-Xsource:3
currently but are not impacted by scala/bug#12437, add-Yscala3-implicit-resolution
to the Scala compiler options to preserve the Scala 2.13.8 behavior of-Xsource:3
flag. Note that even if you are not currently impacted by the bug you may be in the future so the recommendation is not to use-Yscala3-implicit-resolution
unless your code doesn't compile without it (because Scala-3-style implicit resolution is partially broken).If you don't use
-Xsource:3
currently you probably don't want to enable Scala-3-style implicit resolution without using-Xsource:3
so there's no action required for you.