Skip to content

Commit a92cc22

Browse files
lrytzjoroKr21
authored andcommitted
nested refinements
1 parent b8fafdb commit a92cc22

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/compiler/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import scala.collection.mutable.ListBuffer
1818
import symtab.Flags._
1919
import scala.reflect.internal.util.FreshNameCreator
2020
import scala.reflect.internal.util.ListOfNil
21+
import scala.util.chaining._
2122

2223
/** XXX to resolve: TreeGen only assumes global is a SymbolTable, but
2324
* TreeDSL at the moment expects a Global. Can we get by with SymbolTable?
@@ -371,16 +372,16 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
371372
if (isFunction || typeSym.isSubClass(SerializableClass))
372373
anonClass.addAnnotation(SerialVersionUIDAnnotation)
373374

374-
anonClass.setInfo(fun.tpe match {
375-
case tpe @ RefinedType(parents, scope) =>
376-
assert(scope.forall(_.isType), s"Cannot expand function of type $tpe")
377-
ClassInfoType(parents, scope, anonClass)
378-
case tpe =>
379-
val parents =
380-
if (!isFunction) tpe :: Nil
381-
else addSerializable(abstractFunctionType(fun.vparams.map(_.symbol.tpe), fun.body.tpe.deconst))
382-
ClassInfoType(parents, newScope, anonClass)
383-
})
375+
val rScope = newScope
376+
def parents(tp: Type): List[Type] = tp match {
377+
case RefinedType(ps, scope) =>
378+
assert(scope.forall(_.isType), s"Cannot expand function of type $tp")
379+
ps.flatMap(parents).tap(_ => scope.foreach(rScope.enter))
380+
case _ =>
381+
if (!isFunction) tp :: Nil
382+
else addSerializable(abstractFunctionType(fun.vparams.map(_.symbol.tpe), fun.body.tpe.deconst))
383+
}
384+
anonClass.setInfo(ClassInfoType(parents(fun.tpe), rScope, anonClass))
384385

385386
// The original owner is used in the backend for the EnclosingMethod attribute. If fun is
386387
// nested in a value-class method, its owner was already changed to the extension method.

test/files/pos/sammy_refined.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ class Outer {
1818
val t1: T = x => x
1919
val t2: T { type U = String } = x => x
2020
val t3: T { type U } = x => x
21+
val t4: (T { type U }) { type V } = x => x
2122
}

0 commit comments

Comments
 (0)