Skip to content

Commit

Permalink
Perform subtype comparisons in same order as before.
Browse files Browse the repository at this point in the history
Interestingly, swapping the order in which argument subtypes were tested in
`isSubArg` caused

 - one exhaustivity failure (patmat/i9631.scala)
 - one failed compile in the community build (libretto).
 - one reclassification of a neg test to a pos test (i15365.scala)

We should find out at some point why, when we have the time.
  • Loading branch information
odersky committed Jun 30, 2022
1 parent 2165c4f commit a54fac4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
34 changes: 16 additions & 18 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1566,9 +1566,9 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
&& defn.isByNameFunction(arg2.dealias) =>
isSubArg(arg1res, arg2.argInfos.head)
case _ =>
if v > 0 then isSubType(arg1, arg2)
else if v < 0 then isSubType(arg2, arg1)
else isSameType(arg1, arg2)
if v < 0 then isSubType(arg2, arg1)
else if v > 0 then isSubType(arg1, arg2)
else isSameType(arg2, arg1)

isSubArg(args1.head, args2.head)
} && recurArgs(args1.tail, args2.tail, tparams2.tail)
Expand Down Expand Up @@ -2034,22 +2034,20 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def isSameType(tp1: Type, tp2: Type): Boolean =
if tp1 eq NoType then false
else if tp1 eq tp2 then true
else if sames != null && (sames.nn.lookup(tp1) eq tp2) then true
else
sames != null && (sames.nn.lookup(tp1) eq tp2)
|| {
val savedSames = sames
sameLevel += 1
if sameLevel >= startSameTypeTrackingLevel then
Stats.record("cache same type")
sames = new util.EqHashMap()
val res =
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
finally
sameLevel -= 1
sames = savedSames
if res && sames != null then sames.nn(tp2) = tp1
res
}
val savedSames = sames
sameLevel += 1
if sameLevel >= startSameTypeTrackingLevel then
Stats.record("cache same type")
sames = new util.EqHashMap()
val res =
try isSubType(tp1, tp2) && isSubType(tp2, tp1)
finally
sameLevel -= 1
sames = savedSames
if res && sames != null then sames.nn(tp2) = tp1
res

override protected def isSame(tp1: Type, tp2: Type)(using Context): Boolean = isSameType(tp1, tp2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class OptionInputType[TO](ofType: InputType[TO]) extends InputType[Option[TO]]
type Argument[TA]
def argument[Ta](argumentType: InputType[Ta])(implicit fromInput: FromInput[Ta], res: WithoutInputTypeTags[Ta]): Argument[Option[Ta]] = ???

def test = argument(OptionInputType(??? : InputType[WithTag[Boolean, Int]])) :: Nil
def test = argument(OptionInputType(??? : InputType[WithTag[Boolean, Int]])) :: Nil // error

0 comments on commit a54fac4

Please sign in to comment.