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
More accurate outer checks in patterns #8261
Conversation
Pushed another version to try to walk the tightrope between |
@retronym Would this make 2.12.9? |
@eed3si9n No, I'd rather not rush this one. |
Could I remind people about this PR? I still have to compile the Scala.js compiler plugin without |
This PR needs more work before we can merge it. I can't pick it up right now. |
@retronym could you look at this one, please? Even just to get more going on improving it. (I'd like to get rid of the "The outer reference in this type test cannot be checked at run time" exclusion we have in our build.sbt.) |
This comment has been minimized.
This comment has been minimized.
I'm not sure what is the reasoning here 🤔 |
I can't convince myself we know that statically. |
src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
Outdated
Show resolved
Hide resolved
In that case the conclusion could be no - we can't elide the check. |
This comment has been minimized.
This comment has been minimized.
NVM I see that you already use |
Sorry, more docs and a good set of tests are still needed here! The idea is as follows. Given:
Where Is it possible that a value conforms to To answer this, I create a new prefix based on a fresh symbol and check the base type of |
cd6780e
to
1115959
Compare
Thanks. I tried to disprove the assertion with trait BI extends o2.B
class D2 extends o1.B with o1.C with BI
// expected O(1) as outer of value conforming to pattern `b: o1.B`, but got O(2)
def main(args: Array[String]): Unit = {
pat1(new o1.D)
pat1(new D2)
} but it won't let you define such a D2:
which I think I might've seen recently pop up as not being caught in Scala 3, but I might be confusing with something similar looking. I'll try to review the patch. |
src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
Outdated
Show resolved
Hide resolved
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.
LGTM, for its results rather than large sections of how it's done. I understand the intent though. Nice tests and nice fix. I left a couple of questions.
@adriaanm Perhaps you'd also like to take a look at where this ended up. |
src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
Outdated
Show resolved
Hide resolved
Avoids eliding outer checks that matter (run/t11534b.scala) and avoids emitting checks that don't (pos/t11534.scala) which avoids compiler warnings when the tested class doesn't have an outer field. The latter stops the annoying unchecked warning that appeared since a recent refactoring made `TermName` a final class.
1115959
to
1df362c
Compare
Likely going to avoid the risk in 2.12 and land #9504 instead, for 2.13. |
Avoids eliding outer checks that matter (run/t11534b.scala) and
avoids emitting checks that don't (pos/t11534.scala) which avoids
compiler warnings when the tested class doesn't have an outer
field.
The latter stops the annoying unchecked warning that appeared since
a recent refactoring made
TermName
a final class.Fixes scala/bug#11534