File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -350,13 +350,24 @@ trait ConstraintHandling {
350
350
val tpw = tp.widenSingletons
351
351
if (tpw ne tp) && (tpw <:< bound) then tpw else tp
352
352
353
+ def widenEnum (tp : Type ) =
354
+ val tpw = tp.widenEnumCase
355
+ if (tpw ne tp) && (tpw <:< bound) then tpw else tp
356
+
353
357
def isSingleton (tp : Type ): Boolean = tp match
354
358
case WildcardType (optBounds) => optBounds.exists && isSingleton(optBounds.bounds.hi)
355
359
case _ => isSubTypeWhenFrozen(tp, defn.SingletonType )
356
360
361
+ def isEnumCase (tp : Type ): Boolean = tp match
362
+ case WildcardType (optBounds) => optBounds.exists && isEnumCase(optBounds.bounds.hi)
363
+ case _ => tp.classSymbol.isAllOf(EnumCase , butNot= JavaDefined )
364
+
357
365
val wideInst =
358
366
if isSingleton(bound) then inst
359
- else dropSuperTraits(widenOr(widenSingle(inst)))
367
+ else
368
+ val lub = widenOr(widenSingle(inst))
369
+ val asAdt = if isEnumCase(bound) then lub else widenEnum(lub)
370
+ dropSuperTraits(asAdt)
360
371
wideInst match
361
372
case wideInst : TypeRef if wideInst.symbol.is(Module ) =>
362
373
TermRef (wideInst.prefix, wideInst.symbol.sourceModule)
Original file line number Diff line number Diff line change @@ -1146,6 +1146,11 @@ object Types {
1146
1146
case _ => this
1147
1147
}
1148
1148
1149
+ /** if this type is a reference to a class case of an enum, replace it by its first parent */
1150
+ final def widenEnumCase (using Context ): Type = this match
1151
+ case tp : (TypeRef | AppliedType ) if tp.classSymbol.isAllOf(EnumCase ) => tp.parents.head
1152
+ case _ => this
1153
+
1149
1154
/** Widen this type and if the result contains embedded union types, replace
1150
1155
* them by their joins.
1151
1156
* "Embedded" means: inside type lambdas, intersections or recursive types, or in prefixes of refined types.
Original file line number Diff line number Diff line change @@ -1399,8 +1399,8 @@ object Scanners {
1399
1399
1400
1400
object IndentWidth {
1401
1401
private inline val MaxCached = 40
1402
- private val spaces = Array .tabulate(MaxCached + 1 )(new Run (' ' , _))
1403
- private val tabs = Array .tabulate(MaxCached + 1 )(new Run ('\t ' , _))
1402
+ private val spaces = Array .tabulate[ Run ] (MaxCached + 1 )(new Run (' ' , _)) // TODO: remove new after bootstrap
1403
+ private val tabs = Array .tabulate[ Run ] (MaxCached + 1 )(new Run ('\t ' , _)) // TODO: remove new after bootstrap
1404
1404
1405
1405
def Run (ch : Char , n : Int ): Run =
1406
1406
if (n <= MaxCached && ch == ' ' ) spaces(n)
You can’t perform that action at this time.
0 commit comments