@@ -4,7 +4,7 @@ package transform
44
55import core .*
66import Symbols .* , Contexts .* , Types .* , ContextOps .* , Decorators .* , SymDenotations .*
7- import Flags .* , SymUtils .* , NameKinds .*
7+ import Flags .* , SymUtils .* , NameKinds .* , Denotations . Denotation
88import ast .*
99import Names .Name
1010import Phases .Phase
@@ -23,7 +23,7 @@ import reporting.trace
2323import annotation .constructorOnly
2424
2525object Recheck :
26- import tpd .Tree
26+ import tpd .*
2727
2828 /** A flag used to indicate that a ParamAccessor has been temporarily made not-private
2929 * Only used at the start of the Recheck phase, reset at its end.
@@ -36,6 +36,13 @@ object Recheck:
3636 /** Attachment key for rechecked types of TypeTrees */
3737 val RecheckedType = Property .Key [Type ]
3838
39+ val addRecheckedTypes = new TreeMap :
40+ override def transform (tree : Tree )(using Context ): Tree =
41+ val tree1 = super .transform(tree)
42+ tree.getAttachment(RecheckedType ) match
43+ case Some (tpe) => tree1.withType(tpe)
44+ case None => tree1
45+
3946 extension (sym : Symbol )
4047
4148 /** Update symbol's info to newInfo from prevPhase.next to lastPhase.
@@ -129,7 +136,7 @@ abstract class Recheck extends Phase, SymTransformer:
129136 def keepType (tree : Tree ): Boolean = keepAllTypes
130137
131138 /** Constant-folded rechecked type `tp` of tree `tree` */
132- private def constFold (tree : Tree , tp : Type )(using Context ): Type =
139+ protected def constFold (tree : Tree , tp : Type )(using Context ): Type =
133140 val tree1 = tree.withType(tp)
134141 val tree2 = ConstFold (tree1)
135142 if tree2 ne tree1 then tree2.tpe else tp
@@ -141,17 +148,23 @@ abstract class Recheck extends Phase, SymTransformer:
141148 val Select (qual, name) = tree
142149 recheckSelection(tree, recheck(qual).widenIfUnstable, name)
143150
144- /** Keep the symbol of the `select` but re-infer its type */
145- def recheckSelection ( tree : Select , qualType : Type , name : Name )(using Context ) =
151+ def recheckSelection ( tree : Select , qualType : Type , name : Name ,
152+ sharpen : Denotation => Denotation )(using Context ): Type =
146153 if name.is(OuterSelectName ) then tree.tpe
147154 else
148155 // val pre = ta.maybeSkolemizePrefix(qualType, name)
149- val mbr = qualType.findMember(name, qualType,
150- excluded = if tree.symbol.is(Private ) then EmptyFlags else Private
151- ).suchThat(tree.symbol == _)
156+ val mbr = sharpen(
157+ qualType.findMember(name, qualType,
158+ excluded = if tree.symbol.is(Private ) then EmptyFlags else Private
159+ )).suchThat(tree.symbol == _)
152160 constFold(tree, qualType.select(name, mbr))
153161 // .showing(i"recheck select $qualType . $name : ${mbr.info} = $result")
154162
163+
164+ /** Keep the symbol of the `select` but re-infer its type */
165+ def recheckSelection (tree : Select , qualType : Type , name : Name )(using Context ): Type =
166+ recheckSelection(tree, qualType, name, sharpen = identity)
167+
155168 def recheckBind (tree : Bind , pt : Type )(using Context ): Type = tree match
156169 case Bind (name, body) =>
157170 recheck(body, pt)
@@ -444,12 +457,6 @@ abstract class Recheck extends Phase, SymTransformer:
444457
445458 /** Show tree with rechecked types instead of the types stored in the `.tpe` field */
446459 override def show (tree : untpd.Tree )(using Context ): String =
447- val addRecheckedTypes = new TreeMap :
448- override def transform (tree : Tree )(using Context ): Tree =
449- val tree1 = super .transform(tree)
450- tree.getAttachment(RecheckedType ) match
451- case Some (tpe) => tree1.withType(tpe)
452- case None => tree1
453460 atPhase(thisPhase) {
454461 super .show(addRecheckedTypes.transform(tree.asInstanceOf [tpd.Tree ]))
455462 }
0 commit comments