Skip to content
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 #9504

Merged

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Feb 16, 2021

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.

Originally submitted to 2.12.x as #8261.

Fixes scala/bug#11534

@scala-jenkins scala-jenkins added this to the 2.13.6 milestone Feb 16, 2021
@dwijnand dwijnand modified the milestones: 2.13.6, 2.13.5 Feb 16, 2021
@dwijnand dwijnand force-pushed the 2.13/more-accurate-outer-checks-in-patterns branch from 67e77b9 to 5fff7dc Compare February 17, 2021 09:10
@SethTisue

This comment has been minimized.

@lrytz

This comment has been minimized.

@lrytz lrytz self-requested a review February 18, 2021 15:38
@dwijnand

This comment has been minimized.

@SethTisue
Copy link
Member

@lrytz this is the last open ticket or PR for 2.13.5, but it takes time to run the community build.
in the interest of not delaying the release past (hopefully) Tuesday, do you consider this basically safe for merge? if so, can we merge it, so we have a release candidate for the community build? then you could continue reviewing it, meanwhile, and see whether any followup PR (either pre-2.13.5 or post-2.13.5) is needed.

@retronym
Copy link
Member

I'm happy to leave this until post-2.13.5

@dwijnand
Copy link
Member Author

Agreed, this doesn't look ready to me:

testedBinder.info <:< expectedTp: false
expectedTp: Test1.g.TermName
pre: Test1.g.type
testedBinder: value x1
testedBinder.info: sym.NameType
testedBinderClass: type NameType
testedBinderType: sym.NameType
testedBinderType.prefix: sym.type
testedPrefixIsExpectedTypePrefix: false
baseTypeFromFreshPrefix: <notype>
testedPrefixAndExpectedPrefixAreStaticallyIdentical: false
prefixAligns: false

@dwijnand dwijnand marked this pull request as draft February 18, 2021 22:31
@dwijnand dwijnand modified the milestones: 2.13.5, 2.11.13, 2.13.6 Feb 18, 2021
@dwijnand dwijnand force-pushed the 2.13/more-accurate-outer-checks-in-patterns branch from 5fff7dc to 670f5c7 Compare February 18, 2021 22:32
@dwijnand dwijnand changed the title [fport] More accurate outer checks in patterns More accurate outer checks in patterns Feb 22, 2021
@dwijnand dwijnand force-pushed the 2.13/more-accurate-outer-checks-in-patterns branch from 5bf0524 to 6a26cf3 Compare February 22, 2021 08:11
case TypeRef(pre, _, _) if !pre.isStable => // e.g. _: Outer#Inner
false
case TypeRef(pre, sym, args) =>
val testedBinderClass = testedBinder.info.upperBound.typeSymbol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also works. Maybe slightly clearer than .upperBound.

diff --git a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
index c62510e5b2..894fcd834a 100644
--- a/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
+++ b/src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala
@@ -411,7 +411,7 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
                   case TypeRef(pre, _, _) if !pre.isStable => // e.g. _: Outer#Inner
                     false
                   case TypeRef(pre, sym, args) =>
-                    val testedBinderClass = testedBinder.info.upperBound.typeSymbol
+                    val testedBinderClass = testedBinder.info.baseClasses.find(_.isClass).getOrElse(NoSymbol)
                     val testedBinderType = testedBinder.info.baseType(testedBinderClass)

                     val testedPrefixIsExpectedTypePrefix = pre =:= testedBinderType.prefix

@dwijnand dwijnand marked this pull request as ready for review February 24, 2021 13:37
@dwijnand dwijnand force-pushed the 2.13/more-accurate-outer-checks-in-patterns branch from 6a26cf3 to cad94ff Compare March 8, 2021 20:55
@dwijnand dwijnand requested a review from lrytz March 30, 2021 06:16
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Apr 8, 2021
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.
@lrytz lrytz force-pushed the 2.13/more-accurate-outer-checks-in-patterns branch from cad94ff to 350bbe7 Compare April 20, 2021 13:47
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tricky stuff...!

@dwijnand dwijnand enabled auto-merge April 20, 2021 13:59
@dwijnand dwijnand merged commit 79ed5f8 into scala:2.13.x Apr 20, 2021
@dwijnand dwijnand deleted the 2.13/more-accurate-outer-checks-in-patterns branch April 23, 2021 13:05
withOuterTest(withOuterTest(orig)(testedBinder, parent))(testedBinder, copyRefinedType(rt, rest, scope))
case expectedTp =>
val expectedClass = expectedTp.typeSymbol
assert(!expectedClass.isRefinementClass, orig)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This failed, and I think it's because it's failing on xsbti.ScalaProvider with sbt.internal.inc.ScalaInstance.ScalaProvider2 @unchecked. See scala/community-build#1400 (comment). I'm going to try to fix this, but work-stealers welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
5 participants