Skip to content

Commit 0484314

Browse files
authored
Merge pull request #12269 from dotty-staging/fix-12265
Dealias types before testing for isValueSubType
2 parents 2318a81 + a457aa2 commit 0484314

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,17 +1046,15 @@ object Types {
10461046
TypeComparer.isSameTypeWhenFrozen(this, that)
10471047

10481048
/** Is this type a primitive value type which can be widened to the primitive value type `that`? */
1049-
def isValueSubType(that: Type)(using Context): Boolean = widen match {
1049+
def isValueSubType(that: Type)(using Context): Boolean = widenDealias match
10501050
case self: TypeRef if self.symbol.isPrimitiveValueClass =>
1051-
that.widenExpr match {
1051+
that.widenExpr.dealias match
10521052
case that: TypeRef if that.symbol.isPrimitiveValueClass =>
10531053
defn.isValueSubClass(self.symbol, that.symbol)
10541054
case _ =>
10551055
false
1056-
}
10571056
case _ =>
10581057
false
1059-
}
10601058

10611059
def relaxed_<:<(that: Type)(using Context): Boolean =
10621060
(this <:< that) || (this isValueSubType that)

tests/pos/i12265.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object OK {
2+
def apply(n: Int ): Unit = ()
3+
def apply(n: Long): Unit = ()
4+
apply(3) // ok
5+
apply(3L) // ok
6+
}
7+
8+
object KO {
9+
type Key = Int
10+
def apply(n: Key ): Unit = ()
11+
def apply(n: Long): Unit = ()
12+
apply(3) // error
13+
apply(3L) // ok
14+
}

0 commit comments

Comments
 (0)