@@ -4,7 +4,7 @@ package transform
4
4
5
5
import core .*
6
6
import Symbols .* , Contexts .* , Types .* , ContextOps .* , Decorators .* , SymDenotations .*
7
- import Flags .* , SymUtils .* , NameKinds .*
7
+ import Flags .* , SymUtils .* , NameKinds .* , Denotations . Denotation
8
8
import ast .*
9
9
import Names .Name
10
10
import Phases .Phase
@@ -23,7 +23,7 @@ import reporting.trace
23
23
import annotation .constructorOnly
24
24
25
25
object Recheck :
26
- import tpd .Tree
26
+ import tpd .*
27
27
28
28
/** A flag used to indicate that a ParamAccessor has been temporarily made not-private
29
29
* Only used at the start of the Recheck phase, reset at its end.
@@ -36,6 +36,13 @@ object Recheck:
36
36
/** Attachment key for rechecked types of TypeTrees */
37
37
val RecheckedType = Property .Key [Type ]
38
38
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
+
39
46
extension (sym : Symbol )
40
47
41
48
/** Update symbol's info to newInfo from prevPhase.next to lastPhase.
@@ -129,7 +136,7 @@ abstract class Recheck extends Phase, SymTransformer:
129
136
def keepType (tree : Tree ): Boolean = keepAllTypes
130
137
131
138
/** 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 =
133
140
val tree1 = tree.withType(tp)
134
141
val tree2 = ConstFold (tree1)
135
142
if tree2 ne tree1 then tree2.tpe else tp
@@ -141,17 +148,23 @@ abstract class Recheck extends Phase, SymTransformer:
141
148
val Select (qual, name) = tree
142
149
recheckSelection(tree, recheck(qual).widenIfUnstable, name)
143
150
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 =
146
153
if name.is(OuterSelectName ) then tree.tpe
147
154
else
148
155
// 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 == _)
152
160
constFold(tree, qualType.select(name, mbr))
153
161
// .showing(i"recheck select $qualType . $name : ${mbr.info} = $result")
154
162
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
+
155
168
def recheckBind (tree : Bind , pt : Type )(using Context ): Type = tree match
156
169
case Bind (name, body) =>
157
170
recheck(body, pt)
@@ -444,12 +457,6 @@ abstract class Recheck extends Phase, SymTransformer:
444
457
445
458
/** Show tree with rechecked types instead of the types stored in the `.tpe` field */
446
459
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
453
460
atPhase(thisPhase) {
454
461
super .show(addRecheckedTypes.transform(tree.asInstanceOf [tpd.Tree ]))
455
462
}
0 commit comments