@@ -2823,6 +2823,17 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
2823
2823
res
2824
2824
}
2825
2825
2826
+ def isCapturedExistential (sym : Symbol ) =
2827
+ ((sym hasFlag EXISTENTIAL ) && (sym hasFlag CAPTURED )) // todo refine this
2828
+
2829
+ def packCaptured (tpe : Type ): Type = {
2830
+ val captured = mutable.Set [Symbol ]()
2831
+ for (tp <- tpe)
2832
+ if (isCapturedExistential(tp.typeSymbol))
2833
+ captured += tp.typeSymbol
2834
+ existentialAbstraction(captured.toList, tpe)
2835
+ }
2836
+
2826
2837
/** convert skolems to existentials */
2827
2838
def packedType (tree : Tree , owner : Symbol ): Type = {
2828
2839
def defines (tree : Tree , sym : Symbol ) =
@@ -2841,7 +2852,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
2841
2852
def isLocal (sym : Symbol ): Boolean =
2842
2853
if (sym == NoSymbol || sym.isRefinementClass || sym.isLocalDummy) false
2843
2854
else if (owner == NoSymbol ) tree exists (defines(_, sym))
2844
- else containsDef(owner, sym) || isRawParameter(sym) || (( sym hasFlag EXISTENTIAL ) && (sym hasFlag CAPTURED )) // todo refine this
2855
+ else containsDef(owner, sym) || isRawParameter(sym) || isCapturedExistential( sym)
2845
2856
def containsLocal (tp : Type ): Boolean =
2846
2857
tp exists (t => isLocal(t.typeSymbol) || isLocal(t.termSymbol))
2847
2858
val normalizeLocals = new TypeMap {
@@ -3198,7 +3209,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
3198
3209
typed1(atPos(tree.pos) { Function (params, body) }, mode, pt)
3199
3210
} else {
3200
3211
val selector1 = checkDead(typed(selector, EXPRmode | BYVALmode , WildcardType ))
3201
- var cases1 = typedCases(tree, cases, selector1.tpe.widen, pt)
3212
+ var cases1 = typedCases(tree, cases, packCaptured( selector1.tpe.widen) , pt)
3202
3213
3203
3214
if (isPastTyper || ! opt.virtPatmat) {
3204
3215
val (owntype, needAdapt) = ptOrLub(cases1 map (_.tpe))
0 commit comments