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

Propagation of type parameter bounds to wildcard bind patterns loses prefix #8991

Open
scabug opened this issue Nov 18, 2014 · 1 comment
Open
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer
Milestone

Comments

@scabug
Copy link

scabug commented Nov 18, 2014

class Base {
  type N

  class Tree[-T >: N]

  def f(x: Any): Tree[N] = x match {
    case y: Tree[_] => y
  }
}
class Derived extends Base {
  def g(x: Any): Tree[N] = x match {
    case y: Tree[_] => y // fails in both scalac and dotc
  }
}

Here's a patch that makes this typecheck:

diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index a182a2e..dffed83 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -4923,8 +4923,10 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
                 val TypeBounds(lo1, hi1) = tbounds.subst(tparams, argtypes)
                 val lo = lub(List(lo0, lo1))
                 val hi = glb(List(hi0, hi1))
-                if (!(lo =:= lo0 && hi =:= hi0))
-                  asym setInfo logResult(s"Updating bounds of ${asym.fullLocationString} in $tree from '$abounds' to")(TypeBounds(lo, hi))
+                if (!(lo =:= lo0 && hi =:= hi0)) {
+                  val boundsSeenFrom = TypeBounds(lo, hi).asSeenFrom(tpt1.tpe.prefix, tparam.enclClass.owner.enclClass)
+                  asym setInfo logResult(s"Updating bounds of ${asym.fullLocationString} in $tree from '$abounds' to")(boundsSeenFrom)
+                }
               }
               if (asym != null && asym.isAbstractType) {
                 arg match {

Related discussion in dotty: scala/scala3#232

@scabug
Copy link
Author

scabug commented Nov 18, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8991?orig=1
Reporter: @retronym
Affected Versions: 2.11.5

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@som-snytt som-snytt added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) typer
Projects
None yet
Development

No branches or pull requests

3 participants