@@ -13,6 +13,7 @@ import NullOpsDecorator.stripNull
1313import typer .ErrorReporting .err
1414import typer .ProtoTypes .*
1515import typer .TypeAssigner .seqLitType
16+ import typer .ConstFold
1617import config .Printers .recheckr
1718import util .Property
1819import StdNames .nme
@@ -70,6 +71,11 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
7071 sym.updateInfo(reinferResult(sym.info))
7172 case _ =>
7273
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+
7379 def recheckIdent (tree : Ident )(using Context ): Type =
7480 tree.tpe
7581
@@ -83,7 +89,7 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
8389 val mbr = qualType.findMember(name, qualType,
8490 excluded = if tree.symbol.is(Private ) then EmptyFlags else Private
8591 ).suchThat(tree.symbol == )
86- qualType.select(name, mbr)
92+ constFold(tree, qualType.select(name, mbr) )
8793
8894 def recheckBind (tree : Bind , pt : Type )(using Context ): Type = tree match
8995 case Bind (name, body) =>
@@ -147,14 +153,14 @@ abstract class Recheck extends Phase, IdentityDenotTransformer:
147153 assert(formals.isEmpty)
148154 Nil
149155 val argTypes = recheckArgs(tree.args, formals, fntpe.paramRefs)
150- fntpe.instantiate(argTypes)
156+ constFold(tree, fntpe.instantiate(argTypes) )
151157
152158 def recheckTypeApply (tree : TypeApply , pt : Type )(using Context ): Type =
153159 recheck(tree.fun).widen match
154160 case fntpe : PolyType =>
155161 assert(sameLength(fntpe.paramInfos, tree.args))
156162 val argTypes = tree.args.map(recheck(_))
157- fntpe.instantiate(argTypes)
163+ constFold(tree, fntpe.instantiate(argTypes) )
158164
159165 def recheckTyped (tree : Typed )(using Context ): Type =
160166 val tptType = recheck(tree.tpt)
0 commit comments