File tree 4 files changed +42
-2
lines changed 4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -5724,6 +5724,36 @@ object Types {
5724
5724
foldOver(xs, tp)
5725
5725
end NamedPartsAccumulator
5726
5726
5727
+ class ExistsLocalRef (using Context ) extends TypeAccumulator [Boolean ]:
5728
+ val locals = util.HashSet [Type ]()
5729
+ def apply (exists : Boolean , tp : Type ): Boolean =
5730
+ exists || tp.match {
5731
+ case tp : NamedType =>
5732
+ this (false , tp.prefix)
5733
+ case NoPrefix =>
5734
+ true
5735
+ case tp : AppliedType =>
5736
+ foldOver(false , tp)
5737
+ case TypeBounds (lo, hi) =>
5738
+ this (this (false , lo), hi)
5739
+ case tp : ParamRef =>
5740
+ ! locals.contains(tp)
5741
+ case tp : ConstantType =>
5742
+ false
5743
+ case tp : ThisType =>
5744
+ false
5745
+ case tl : HKTypeLambda =>
5746
+ locals ++= tl.paramRefs
5747
+ foldOver(false , tl)
5748
+ case tp : RecThis =>
5749
+ false
5750
+ case tp : LazyRef =>
5751
+ false
5752
+ case _ =>
5753
+ foldOver(false , tp)
5754
+ }
5755
+ end ExistsLocalRef
5756
+
5727
5757
class isGroundAccumulator (using Context ) extends TypeAccumulator [Boolean ] {
5728
5758
def apply (x : Boolean , tp : Type ): Boolean = x && {
5729
5759
tp match {
Original file line number Diff line number Diff line change @@ -41,7 +41,11 @@ trait TypeAssigner {
41
41
}
42
42
43
43
def avoidingType (expr : Tree , bindings : List [Tree ])(using Context ): Type =
44
- TypeOps .avoid(expr.tpe, localSyms(bindings).filterConserve(_.isTerm))
44
+ val refersLocal = ExistsLocalRef ()(false , expr.tpe)
45
+ if refersLocal then
46
+ TypeOps .avoid(expr.tpe, localSyms(bindings).filterConserve(_.isTerm))
47
+ else
48
+ expr.tpe
45
49
46
50
def avoidPrivateLeaks (sym : Symbol )(using Context ): Type =
47
51
if sym.owner.isClass && ! sym.isOneOf(JavaOrPrivateOrSynthetic )
Original file line number Diff line number Diff line change @@ -1007,7 +1007,11 @@ class Typer extends Namer
1007
1007
case _ =>
1008
1008
Typed (tree, TypeTree (pt.simplified))
1009
1009
}
1010
- def noLeaks (t : Tree ): Boolean = escapingRefs(t, localSyms).isEmpty
1010
+
1011
+ def noLeaks (t : Tree ): Boolean =
1012
+ val refersLocal = ExistsLocalRef ()(false , tree.tpe)
1013
+ ! refersLocal || escapingRefs(t, localSyms).isEmpty
1014
+
1011
1015
if (noLeaks(tree)) tree
1012
1016
else {
1013
1017
fullyDefinedType(tree.tpe, " block" , tree.span)
Original file line number Diff line number Diff line change @@ -61,3 +61,5 @@ i9793.scala
61
61
# lazy_implicit symbol has different position after pickling
62
62
i8182.scala
63
63
64
+ # trivial recursive type gets stripped
65
+ i11464.scala
You can’t perform that action at this time.
0 commit comments