Skip to content

Commit aea28b9

Browse files
committed
Simplify the type member extractor logic.
And improve the error message on selecting a class member of an unstable prefix.
1 parent bff2de6 commit aea28b9

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3355,8 +3355,9 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
33553355
stableScrut.member(typeMemberName) match
33563356
case denot: SingleDenotation if denot.exists =>
33573357
val info = denot.info match
3358-
case TypeAlias(alias) => alias
3359-
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
3358+
case TypeAlias(alias) => alias // Extract the alias
3359+
case ClassInfo(prefix, cls, _, _, _) => prefix.select(cls) // Re-select the class from the prefix
3360+
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
33603361
val infoRefersToSkolem = stableScrut match
33613362
case stableScrut: SkolemType =>
33623363
new TypeAccumulator[Boolean] {
@@ -3365,26 +3366,11 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
33653366
}.apply(false, info)
33663367
case _ =>
33673368
false
3368-
if infoRefersToSkolem && info.isInstanceOf[ClassInfo] then
3369-
/* We would like to create a `RealTypeBounds(info, info)` to get a `MatchResult.NoInstances`
3370-
* but that is not allowed for `ClassInfo`. So instead we return `false`, which will result
3371-
* in a `MatchResult.Stuck` instead.
3372-
*/
3373-
false
3374-
else
3375-
val info1 = info match
3376-
case ClassInfo(prefix, cls, _, _, _) =>
3377-
// Re-select the class from the prefix
3378-
prefix.select(cls)
3379-
case info: TypeBounds =>
3380-
// Will already trigger a MatchResult.NoInstances
3381-
info
3382-
case _ if infoRefersToSkolem =>
3383-
// Explicitly trigger a MatchResult.NoInstances
3384-
RealTypeBounds(info, info)
3385-
case _ =>
3386-
info
3387-
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
3369+
val info1 = info match
3370+
case info: TypeBounds => info // Will already trigger a MatchResult.NoInstances
3371+
case _ if infoRefersToSkolem => RealTypeBounds(info, info) // Explicitly trigger a MatchResult.NoInstances
3372+
case _ => info // We have a match
3373+
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
33883374
case _ =>
33893375
false
33903376
end rec

tests/neg/match-type-enumeration-value-hack.check

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
|
88
| trying to reduce EnumValue[Suit]
99
| failed since selector Suit
10-
| does not match case EnumValueAux[t] => t
11-
| and cannot be shown to be disjoint from it either.
10+
| does not uniquely determine parameter t in
11+
| case EnumValueAux[t] => t
12+
| The computed bounds for the parameter are:
13+
| t >: ?1.Value <: ?1.Value

0 commit comments

Comments
 (0)