Skip to content

Commit 7c561a2

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 80f64e5 commit 7c561a2

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
@@ -3359,8 +3359,9 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
33593359
stableScrut.member(typeMemberName) match
33603360
case denot: SingleDenotation if denot.exists =>
33613361
val info = denot.info match
3362-
case TypeAlias(alias) => alias
3363-
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
3362+
case TypeAlias(alias) => alias // Extract the alias
3363+
case ClassInfo(prefix, cls, _, _, _) => prefix.select(cls) // Re-select the class from the prefix
3364+
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
33643365
val infoRefersToSkolem = stableScrut match
33653366
case stableScrut: SkolemType =>
33663367
new TypeAccumulator[Boolean] {
@@ -3369,26 +3370,11 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
33693370
}.apply(false, info)
33703371
case _ =>
33713372
false
3372-
if infoRefersToSkolem && info.isInstanceOf[ClassInfo] then
3373-
/* We would like to create a `RealTypeBounds(info, info)` to get a `MatchResult.NoInstances`
3374-
* but that is not allowed for `ClassInfo`. So instead we return `false`, which will result
3375-
* in a `MatchResult.Stuck` instead.
3376-
*/
3377-
false
3378-
else
3379-
val info1 = info match
3380-
case ClassInfo(prefix, cls, _, _, _) =>
3381-
// Re-select the class from the prefix
3382-
prefix.select(cls)
3383-
case info: TypeBounds =>
3384-
// Will already trigger a MatchResult.NoInstances
3385-
info
3386-
case _ if infoRefersToSkolem =>
3387-
// Explicitly trigger a MatchResult.NoInstances
3388-
RealTypeBounds(info, info)
3389-
case _ =>
3390-
info
3391-
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
3373+
val info1 = info match
3374+
case info: TypeBounds => info // Will already trigger a MatchResult.NoInstances
3375+
case _ if infoRefersToSkolem => RealTypeBounds(info, info) // Explicitly trigger a MatchResult.NoInstances
3376+
case _ => info // We have a match
3377+
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
33923378
case _ =>
33933379
false
33943380
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)