Skip to content

Commit

Permalink
WIP fix scala#4790, part 1: recognize closed hiearchies
Browse files Browse the repository at this point in the history
Must also check if those closed hierarchies prevent refinement.
  • Loading branch information
Blaisorblade committed Aug 14, 2018
1 parent b4670b7 commit 7a6fc60
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import config.Printers.{typr, constr}
import annotation.tailrec
import reporting._
import collection.mutable
import transform.SymUtils._
import config.Config

import scala.annotation.internal.sharable
Expand Down Expand Up @@ -191,8 +192,10 @@ object Inferencing {
* TODO: Update so that GADT symbols can be variant, and we special case final class types in patterns
*/
def constrainPatternType(tp: Type, pt: Type)(implicit ctx: Context): Boolean = {
def refinementIsInvariantCls(cls: Symbol): Boolean =
cls.is(Final) || cls.is(Case) || cls.is(Sealed) && cls.children.forall(refinementIsInvariantCls)
def refinementIsInvariant(tp: Type): Boolean = tp match {
case tp: ClassInfo => tp.cls.is(Final) || tp.cls.is(Case)
case tp: ClassInfo => refinementIsInvariantCls(tp.cls)
case tp: TypeProxy => refinementIsInvariant(tp.underlying)
case tp: AndType => refinementIsInvariant(tp.tp1) && refinementIsInvariant(tp.tp2)
case tp: OrType => refinementIsInvariant(tp.tp1) && refinementIsInvariant(tp.tp2)
Expand Down

0 comments on commit 7a6fc60

Please sign in to comment.