File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change @@ -59,15 +59,6 @@ object ConstFold:
5959 tree.withFoldedType(Constant (targ.tpe))
6060 case _ => tree
6161
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-
7162 extension [T <: Tree ](tree : T )(using Context )
7263 private def withFoldedType (c : Constant | Null ): T =
7364 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
34233423
34243424 def adaptToSubType (wtp : Type ): Tree = {
34253425 // try converting a constant to the target type
3426- val folded = ConstFold (tree, pt)
3427- if (folded ne tree)
3428- return adaptConstant(tree, 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 _ =>
34293432
34303433 val captured = captureWildcards(wtp)
34313434 if (captured `ne` wtp)
You can’t perform that action at this time.
0 commit comments