@@ -13,6 +13,7 @@ import NullOpsDecorator.stripNull
13
13
import typer .ErrorReporting .err
14
14
import typer .ProtoTypes .*
15
15
import typer .TypeAssigner .seqLitType
16
+ import typer .ConstFold
16
17
import config .Printers .recheckr
17
18
import util .Property
18
19
import StdNames .nme
@@ -70,6 +71,11 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
70
71
sym.updateInfo(reinferResult(sym.info))
71
72
case _ =>
72
73
74
+ def constFold (tree : Tree , tp : Type )(using Context ): Type =
75
+ val tree1 = tree.withType(tp)
76
+ val tree2 = ConstFold (tree1)
77
+ if tree2 ne tree1 then tree2.tpe else tp
78
+
73
79
def recheckIdent (tree : Ident )(using Context ): Type =
74
80
tree.tpe
75
81
@@ -83,7 +89,7 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
83
89
val mbr = qualType.findMember(name, qualType,
84
90
excluded = if tree.symbol.is(Private ) then EmptyFlags else Private
85
91
).suchThat(tree.symbol == )
86
- qualType.select(name, mbr)
92
+ constFold(tree, qualType.select(name, mbr) )
87
93
88
94
def recheckBind (tree : Bind , pt : Type )(using Context ): Type = tree match
89
95
case Bind (name, body) =>
@@ -147,14 +153,14 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
147
153
assert(formals.isEmpty)
148
154
Nil
149
155
val argTypes = recheckArgs(tree.args, formals, fntpe.paramRefs)
150
- fntpe.instantiate(argTypes)
156
+ constFold(tree, fntpe.instantiate(argTypes) )
151
157
152
158
def recheckTypeApply (tree : TypeApply , pt : Type )(using Context ): Type =
153
159
recheck(tree.fun).widen match
154
160
case fntpe : PolyType =>
155
161
assert(sameLength(fntpe.paramInfos, tree.args))
156
162
val argTypes = tree.args.map(recheck(_))
157
- fntpe.instantiate(argTypes)
163
+ constFold(tree, fntpe.instantiate(argTypes) )
158
164
159
165
def recheckTyped (tree : Typed )(using Context ): Type =
160
166
val tptType = recheck(tree.tpt)
0 commit comments