Skip to content

Commit a457aa2

Browse files
committed
Dealias types before testing for isValueSubType
Fixes #12265
1 parent 1e484e5 commit a457aa2

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

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

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

10401040
/** Is this type a primitive value type which can be widened to the primitive value type `that`? */
1041-
def isValueSubType(that: Type)(using Context): Boolean = widen match {
1041+
def isValueSubType(that: Type)(using Context): Boolean = widenDealias match
10421042
case self: TypeRef if self.symbol.isPrimitiveValueClass =>
1043-
that.widenExpr match {
1043+
that.widenExpr.dealias match
10441044
case that: TypeRef if that.symbol.isPrimitiveValueClass =>
10451045
defn.isValueSubClass(self.symbol, that.symbol)
10461046
case _ =>
10471047
false
1048-
}
10491048
case _ =>
10501049
false
1051-
}
10521050

10531051
def relaxed_<:<(that: Type)(using Context): Boolean =
10541052
(this <:< that) || (this isValueSubType that)

tasty/test/dotty/tools/tasty/TastyHeaderUnpicklerTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ object TastyHeaderUnpicklerTest {
5757
buf.writeNat(exp)
5858
buf.writeNat(compilerBytes.length)
5959
buf.writeBytes(compilerBytes, compilerBytes.length)
60-
buf.writeUncompressedLong(237478l)
61-
buf.writeUncompressedLong(324789l)
60+
buf.writeUncompressedLong(237478L)
61+
buf.writeUncompressedLong(324789L)
6262
buf
6363
}
6464

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)