Skip to content

Commit a32650b

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 11e03a0 commit a32650b

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
@@ -3363,29 +3363,15 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
33633363
stableScrut.member(typeMemberName) match
33643364
case denot: SingleDenotation if denot.exists =>
33653365
val info = denot.info match
3366-
case TypeAlias(alias) => alias
3367-
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
3366+
case TypeAlias(alias) => alias // Extract the alias
3367+
case ClassInfo(prefix, cls, _, _, _) => prefix.select(cls) // Re-select the class from the prefix
3368+
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
33683369
val infoRefersToSkolem = stableScrut.isInstanceOf[SkolemType] && stableScrut.occursIn(info)
3369-
if infoRefersToSkolem && info.isInstanceOf[ClassInfo] then
3370-
/* We would like to create a `RealTypeBounds(info, info)` to get a `MatchResult.NoInstances`
3371-
* but that is not allowed for `ClassInfo`. So instead we return `false`, which will result
3372-
* in a `MatchResult.Stuck` instead.
3373-
*/
3374-
false
3375-
else
3376-
val info1 = info match
3377-
case ClassInfo(prefix, cls, _, _, _) =>
3378-
// Re-select the class from the prefix
3379-
prefix.select(cls)
3380-
case info: TypeBounds =>
3381-
// Will already trigger a MatchResult.NoInstances
3382-
info
3383-
case _ if infoRefersToSkolem =>
3384-
// Explicitly trigger a MatchResult.NoInstances
3385-
RealTypeBounds(info, info)
3386-
case _ =>
3387-
info
3388-
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
3370+
val info1 = info match
3371+
case info: TypeBounds => info // Will already trigger a MatchResult.NoInstances
3372+
case _ if infoRefersToSkolem => RealTypeBounds(info, info) // Explicitly trigger a MatchResult.NoInstances
3373+
case _ => info // We have a match
3374+
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
33893375
case _ =>
33903376
false
33913377
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)