File tree 3 files changed +24
-12
lines changed
compiler/src/dotty/tools/dotc/typer 3 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -59,15 +59,6 @@ object ConstFold:
59
59
tree.withFoldedType(Constant (targ.tpe))
60
60
case _ => tree
61
61
62
- /** If tree is a constant value that can be converted to type `pt`, perform
63
- * the conversion.
64
- */
65
- def apply [T <: Tree ](tree : T , pt : Type )(using Context ): T =
66
- val tree1 = apply(tree)
67
- tree.tpe.widenTermRefExpr.normalized match
68
- case ConstantType (x) => tree1.withFoldedType(x.convertTo(pt))
69
- case _ => tree1
70
-
71
62
extension [T <: Tree ](tree : T )(using Context )
72
63
private def withFoldedType (c : Constant | Null ): T =
73
64
if c == null then tree else tree.withType(ConstantType (c)).asInstanceOf [T ]
Original file line number Diff line number Diff line change @@ -3423,9 +3423,12 @@ class Typer extends Namer
3423
3423
3424
3424
def adaptToSubType (wtp : Type ): Tree = {
3425
3425
// try converting a constant to the target type
3426
- val folded = ConstFold (tree, pt)
3427
- if (folded ne tree)
3428
- return adaptConstant(folded, folded.tpe.asInstanceOf [ConstantType ])
3426
+ ConstFold (tree).tpe.widenTermRefExpr.normalized match
3427
+ case ConstantType (x) =>
3428
+ val converted = x.convertTo(pt)
3429
+ if converted != null && (converted ne x) then
3430
+ return adaptConstant(tree, ConstantType (converted))
3431
+ case _ =>
3429
3432
3430
3433
val captured = captureWildcards(wtp)
3431
3434
if (captured `ne` wtp)
Original file line number Diff line number Diff line change
1
+ object OverloadedWithLong {
2
+ def overloaded (x : Long ): Any =
3
+ x
4
+
5
+ def overloaded (x : Any ): Unit =
6
+ ???
7
+ }
8
+
9
+ object Test {
10
+ def main (args : Array [String ]): Unit =
11
+ import OverloadedWithLong ._
12
+
13
+ val l : Any = 0 :: Nil
14
+ val r = overloaded(l match {
15
+ case x :: xs => 5
16
+ })
17
+ assert(r == 5L )
18
+ }
You can’t perform that action at this time.
0 commit comments