Skip to content

Commit 54fe387

Browse files
Keep the unsound behavior under a -Y flag
1 parent 03b2d42 commit 54fe387

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {
200200
val YerasedTerms: Setting[Boolean] = BooleanSetting("-Yerased-terms", "Allows the use of erased terms.")
201201
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ycheck-init", "Check initialization of objects")
202202
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
203+
val YunsoundMatchTypes: Setting[Boolean] = BooleanSetting("-Yunsound-match-types", "Use unsound match type reduction algorithm.")
203204

204205
/** Area-specific debug output */
205206
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,16 +2511,20 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
25112511
case (_, tp2: NamedType) if gadtBounds(tp2.symbol) != null =>
25122512
provablyDisjoint(tp1, gadtBounds(tp2.symbol).hi) || provablyDisjoint(tp1, tp2.superType)
25132513
case (tp1: TypeProxy, tp2: TypeProxy) =>
2514-
provablyDisjoint(tp1.superType, tp2) || provablyDisjoint(tp1, tp2.superType)
2514+
provablyDisjoint(matchTypeSuperType(tp1), tp2) || provablyDisjoint(tp1, matchTypeSuperType(tp2))
25152515
case (tp1: TypeProxy, _) =>
2516-
provablyDisjoint(tp1.superType, tp2)
2516+
provablyDisjoint(matchTypeSuperType(tp1), tp2)
25172517
case (_, tp2: TypeProxy) =>
2518-
provablyDisjoint(tp1, tp2.superType)
2518+
provablyDisjoint(tp1, matchTypeSuperType(tp2))
25192519
case _ =>
25202520
false
25212521
}
25222522
}
25232523

2524+
/** Restores the buggy match type reduction under -Yunsound-match-types. */
2525+
private def matchTypeSuperType(tp: TypeProxy): Type =
2526+
if ctx.settings.YunsoundMatchTypes.value then tp.underlying else tp.superType
2527+
25242528
protected def explainingTypeComparer = ExplainingTypeComparer(comparerContext)
25252529
protected def trackingTypeComparer = TrackingTypeComparer(comparerContext)
25262530

0 commit comments

Comments
 (0)