Skip to content

Commit

Permalink
Dealias val aliases to modules so they're =:=
Browse files Browse the repository at this point in the history
This changes the definitely of =:= in the smallest possible way:
if you have a singleton type that widens to a module,
then widen to that module.
  • Loading branch information
dwijnand committed Nov 12, 2020
1 parent 8507cf0 commit ae5f764
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -4558,9 +4558,9 @@ trait Types
if (isRawType(tp)) rawToExistential(tp)
else tp.normalize match {
// Unify the representations of module classes
case st@SingleType(_, sym) if sym.isModule => st.underlying.normalize
case st@ThisType(sym) if sym.isModuleClass => normalizePlus(st.underlying)
case _ => tp.normalize
case st @ SingleType(_, sym) if st.dealiasWiden.typeSymbol.isModuleOrModuleClass => st.dealiasWiden.normalize
case st @ ThisType(sym) if sym.isModuleClass => normalizePlus(st.underlying)
case tpNorm => tpNorm
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/files/pos/t12186.scala
@@ -0,0 +1,29 @@
// scalac: -Werror

// this is remodeling of the scala package object and scala.collection.immutable.{ List, ::, Nil }
// in order to:
// * avoid the scala package, which is auto-imported
// * avoid List, which is rewritten/fudged in the pattern matcher
package skala.collect {
sealed trait Xs[+A]
final case class Cons[+A](head: A, tail: Xs[A]) extends Xs[A]
final case object Done extends Xs[Nothing]
object Xs
}
package object skala {
type Cons[+A] = skala.collect.Cons[A]
type Xs[+A] = skala.collect.Xs[A]
val Cons = skala.collect.Cons
val Done: skala.collect.Done.type = skala.collect.Done
val Xs = skala.collect.Xs
}

import skala._

class Test {
def test(xs: Xs[Int]): Boolean = xs match {
case Cons(_, _) => true
case _: Done.type => false
//case _: skala.collect.Done.type => false // done this way it already works
}
}

0 comments on commit ae5f764

Please sign in to comment.