Skip to content

Commit c3ae358

Browse files
committed
Revert #11784
The original PR fixes a trivial issue. However, the fix has both false positives and negatives. It's not easy to do the right thing. Therefore, it's simpler to remove the original fixes.
1 parent 67ffb4b commit c3ae358

File tree

2 files changed

+5
-59
lines changed

2 files changed

+5
-59
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,65 +4364,11 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43644364
withMode(Mode.GadtConstraintInference) {
43654365
TypeComparer.constrainPatternType(tree.tpe, pt)
43664366
}
4367-
4368-
// approximate type params with bounds
4369-
def approx = new ApproximatingTypeMap {
4370-
var alreadyExpanding: List[TypeRef] = Nil
4371-
def apply(tp: Type) = tp.dealias match
4372-
case tp: TypeRef if !tp.symbol.isClass =>
4373-
if alreadyExpanding contains tp then tp else
4374-
val saved = alreadyExpanding
4375-
alreadyExpanding ::= tp
4376-
val res = expandBounds(tp.info.bounds)
4377-
alreadyExpanding = saved
4378-
res
4379-
case _ =>
4380-
mapOver(tp)
4381-
}
4382-
4383-
// Is it possible that a value of `clsA` is equal to a value of `clsB`?
4384-
// This ignores user-defined equals methods, but makes an exception
4385-
// for numeric classes.
4386-
def canOverlap(clsA: ClassSymbol, clsB: ClassSymbol): Boolean =
4387-
clsA.mayHaveCommonChild(clsB)
4388-
|| clsA.isNumericValueClass // this is quite coarse, but matches to what was done before
4389-
|| clsB.isNumericValueClass
4390-
4391-
// Can type `a` possiblly have a common instance with type `b`?
4392-
def canEqual(a: Type, b: Type): Boolean = trace(i"canEqual $a $b"):
4393-
b match
4394-
case _: TypeRef | _: AppliedType if b.typeSymbol.isClass =>
4395-
a match
4396-
case a: TermRef if a.symbol.isOneOf(Module | Enum) =>
4397-
(a frozen_<:< b) // fast track
4398-
|| (a frozen_<:< approx(b))
4399-
case _: TypeRef | _: AppliedType if a.typeSymbol.isClass =>
4400-
if a.isNullType then !b.isNotNull
4401-
else canOverlap(a.typeSymbol.asClass, b.typeSymbol.asClass)
4402-
case a: TypeProxy =>
4403-
canEqual(a.superType, b)
4404-
case a: AndOrType =>
4405-
canEqual(a.tp1, b) || canEqual(a.tp2, b)
4406-
case b: TypeProxy =>
4407-
canEqual(a, b.superType)
4408-
case b: AndOrType =>
4409-
// we lose precision with and/or types, but it's hard to do better and
4410-
// still compute `canEqual(A & B, B & A) = true`.
4411-
canEqual(a, b.tp1) || canEqual(a, b.tp2)
4412-
4413-
if !canEqual(tree.tpe, pt) then
4414-
// We could check whether `equals` is overridden.
4415-
// Reasons for not doing so:
4416-
// - it complicates the protocol
4417-
// - such code patterns usually implies hidden errors in the code
4418-
// - it's safe/sound to reject the code
4419-
report.error(TypeMismatch(tree.tpe, pt, Some(tree), "\npattern type is incompatible with expected type"), tree.srcPos)
4420-
else
4421-
val cmp =
4422-
untpd.Apply(
4423-
untpd.Select(untpd.TypedSplice(tree), nme.EQ),
4424-
untpd.TypedSplice(dummyTreeOfType(pt)))
4425-
typedExpr(cmp, defn.BooleanType)
4367+
val cmp =
4368+
untpd.Apply(
4369+
untpd.Select(untpd.TypedSplice(tree), nme.EQ),
4370+
untpd.TypedSplice(dummyTreeOfType(pt)))
4371+
typedExpr(cmp, defn.BooleanType)
44264372
case _ =>
44274373

44284374
private def checkInterestingResultInStatement(t: Tree)(using Context): Boolean = {
File renamed without changes.

0 commit comments

Comments
 (0)