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

Incorrect pattern matching type check for path-dependent types #9779

Open
scabug opened this issue May 17, 2016 · 1 comment
Open

Incorrect pattern matching type check for path-dependent types #9779

scabug opened this issue May 17, 2016 · 1 comment

Comments

@scabug
Copy link

scabug commented May 17, 2016

Minimal example at https://gist.github.com/retronym/41084b66d1df9904558d63797c579a2c, thanks to Jason Zaugg:

trait Elems {
  class Elem[A] extends Dummy

  val UnitElement: Elem[Unit]

  // Workaround 1: if you use an object rather than a val, the typechecker
  // uses GADT refinement to adapt the patten type of `a.Elem[Unit]` to
  // `a.Elem[$1]`. See `inferModulePattern`, which calls `instantiateTypeParams`.
  //
  // object UnitElement extends Elem[Unit]

  // Workaround 2: Define `Dummy` at the top level, rather than
  // as a member of `Elems`. Even without GADT refinement, the
  // check for `isPopulated(BadMatch.this.a.Elem[Unit], ?#Elem[?]`)
  // seems to be happy that there is a value that inhabits both
  // types.
  //
  // I think thie problem here is that `?#Elem[?]`.baseType(DummyClass)
  // returns `Elems.this.Dummy`, rather than `?#Dummy`. (? is the
  // Wildcard type).
  //
  // We should update `AsSeenFromMap` as follows to fix this:
  //
  //   diff --git a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
  // index af51281..316db7a 100644
  // --- a/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
  // +++ b/src/reflect/scala/reflect/internal/tpe/TypeMaps.scala
  // @@ -616,3 +616,3 @@ private[internal] trait TypeMaps {
  //      private def matchesPrefixAndClass(pre: Type, clazz: Symbol)(candidate: Symbol) =
  // -      (clazz == candidate) && (pre.widen.typeSymbol isSubClass clazz)
  // +      (clazz == candidate) && ((pre.widen.typeSymbol isSubClass clazz) || (pre eq WildcardType))

  trait Dummy


}

class BadMatch[A <: Elems](a: A) {
  def toLuaValue(eX: a.Elem[_]): String = eX match {
    case a.UnitElement => "" // type mismatch
  }
}
@scabug
Copy link
Author

scabug commented May 17, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9779?orig=1
Reporter: @alexeyr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants