File tree 3 files changed +39
-2
lines changed
compiler/src/dotty/tools/dotc
3 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import ast.tpd._
13
13
import reporting .trace
14
14
import config .Printers .typr
15
15
import config .Feature
16
+ import transform .SymUtils .*
16
17
import typer .ProtoTypes ._
17
18
import typer .ForceDegree
18
19
import typer .Inferencing ._
@@ -846,14 +847,23 @@ object TypeOps:
846
847
var prefixTVar : Type | Null = null
847
848
def apply (tp : Type ): Type = tp match {
848
849
case ThisType (tref : TypeRef ) if ! tref.symbol.isStaticOwner =>
850
+ val symbol = tref.symbol
849
851
if (tref.symbol.is(Module ))
850
852
TermRef (this (tref.prefix), tref.symbol.sourceModule)
851
853
else if (prefixTVar != null )
852
854
this (tref)
853
855
else {
854
856
prefixTVar = WildcardType // prevent recursive call from assigning it
855
- val tref2 = this (tref.applyIfParameterized(tref.typeParams.map(_ => TypeBounds .empty)))
856
- prefixTVar = newTypeVar(TypeBounds .upper(tref2))
857
+ prefixTVar = if symbol.is(Sealed ) && symbol.isOneOf(AbstractOrTrait ) && symbol.children.sizeIs > 0 && ! symbol.hasAnonymousChild then
858
+ symbol.children.foldLeft(WildcardType : Type ) { (acc, c) =>
859
+ val tp = this (c.appliedRef) match
860
+ case tp : TypeRef if tp.symbol.is(ModuleVal ) => tp.symbol.moduleClass.denot.thisType
861
+ case tp => tp
862
+ acc | tp
863
+ }
864
+ else
865
+ val tref2 = this (tref.applyIfParameterized(tref.typeParams.map(_ => TypeBounds .empty)))
866
+ newTypeVar(TypeBounds .upper(tref2))
857
867
prefixTVar.uncheckedNN
858
868
}
859
869
case tp => mapOver(tp)
Original file line number Diff line number Diff line change @@ -628,6 +628,13 @@ class SpaceEngine(using Context) extends SpaceLogic {
628
628
Typ (ConstantType (Constant (())), true ) :: Nil
629
629
case tp if tp.classSymbol.isAllOf(JavaEnumTrait ) =>
630
630
tp.classSymbol.children.map(sym => Typ (sym.termRef, true ))
631
+
632
+ case tp @ AppliedType (tycon, targs) if tp.classSymbol.children.isEmpty && canDecompose(tycon) =>
633
+ rec(tycon, Nil ).map(typ => Typ (tp.derivedAppliedType(typ.tp, targs)))
634
+
635
+ case tp : NamedType if canDecompose(tp.prefix) =>
636
+ rec(tp.prefix, Nil ).map(typ => Typ (tp.derivedSelect(typ.tp)))
637
+
631
638
case tp =>
632
639
def getChildren (sym : Symbol ): List [Symbol ] =
633
640
sym.children.flatMap { child =>
@@ -669,6 +676,8 @@ class SpaceEngine(using Context) extends SpaceLogic {
669
676
/** Abstract sealed types, or-types, Boolean and Java enums can be decomposed */
670
677
def canDecompose (tp : Type ): Boolean =
671
678
val res = tp.dealias match
679
+ case tp : AppliedType => canDecompose(tp.tycon)
680
+ case tp : NamedType if tp.classSymbol.children.isEmpty => canDecompose(tp.prefix)
672
681
case _ : SingletonType => false
673
682
case _ : OrType => true
674
683
case and : AndType => canDecompose(and.tp1) || canDecompose(and.tp2)
Original file line number Diff line number Diff line change
1
+ // scalac: -Werror
2
+ sealed trait Schema [A ]
3
+
4
+ sealed trait RecordInstances :
5
+ case class Field [B ]() extends Schema [B ]
6
+ case object Thing extends Schema [Int ]
7
+
8
+ object X extends RecordInstances
9
+ object Y extends RecordInstances
10
+
11
+ // Match not exhaustive error! (with fatal warnings :P)
12
+ class Test :
13
+ def handle [T ](schema : Schema [T ]) =
14
+ schema match // was: match may not be exhaustive
15
+ case X .Field () =>
16
+ case X .Thing =>
17
+ case Y .Field () =>
18
+ case Y .Thing =>
You can’t perform that action at this time.
0 commit comments