Skip to content

Commit

Permalink
Simplify the type member extractor logic.
Browse files Browse the repository at this point in the history
And improve the error message on selecting a class member of an
unstable prefix.
  • Loading branch information
sjrd committed Aug 15, 2023
1 parent bff2de6 commit aea28b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
30 changes: 8 additions & 22 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3355,8 +3355,9 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
stableScrut.member(typeMemberName) match
case denot: SingleDenotation if denot.exists =>
val info = denot.info match
case TypeAlias(alias) => alias
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
case TypeAlias(alias) => alias // Extract the alias
case ClassInfo(prefix, cls, _, _, _) => prefix.select(cls) // Re-select the class from the prefix
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
val infoRefersToSkolem = stableScrut match
case stableScrut: SkolemType =>
new TypeAccumulator[Boolean] {
Expand All @@ -3365,26 +3366,11 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
}.apply(false, info)
case _ =>
false
if infoRefersToSkolem && info.isInstanceOf[ClassInfo] then
/* We would like to create a `RealTypeBounds(info, info)` to get a `MatchResult.NoInstances`
* but that is not allowed for `ClassInfo`. So instead we return `false`, which will result
* in a `MatchResult.Stuck` instead.
*/
false
else
val info1 = info match
case ClassInfo(prefix, cls, _, _, _) =>
// Re-select the class from the prefix
prefix.select(cls)
case info: TypeBounds =>
// Will already trigger a MatchResult.NoInstances
info
case _ if infoRefersToSkolem =>
// Explicitly trigger a MatchResult.NoInstances
RealTypeBounds(info, info)
case _ =>
info
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
val info1 = info match
case info: TypeBounds => info // Will already trigger a MatchResult.NoInstances
case _ if infoRefersToSkolem => RealTypeBounds(info, info) // Explicitly trigger a MatchResult.NoInstances
case _ => info // We have a match
rec(capture, info1, variance = 0, scrutIsWidenedAbstract)
case _ =>
false
end rec
Expand Down
6 changes: 4 additions & 2 deletions tests/neg/match-type-enumeration-value-hack.check
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
|
| trying to reduce EnumValue[Suit]
| failed since selector Suit
| does not match case EnumValueAux[t] => t
| and cannot be shown to be disjoint from it either.
| does not uniquely determine parameter t in
| case EnumValueAux[t] => t
| The computed bounds for the parameter are:
| t >: ?1.Value <: ?1.Value

0 comments on commit aea28b9

Please sign in to comment.