@@ -75,6 +75,35 @@ trait DottyTest extends ContextEscapeDetection {
7575 run.runContext
7676 }
7777
78+ def checkTypes (source : String , typeStrings : String * )(assertion : (List [Type ], Context ) => Unit ): Unit =
79+ checkTypes(source, List (typeStrings.toList)) { (tpess, ctx) => (tpess : @ unchecked) match {
80+ case List (tpes) => assertion(tpes, ctx)
81+ }}
82+
83+ def checkTypes (source : String , typeStringss : List [List [String ]])(assertion : (List [List [Type ]], Context ) => Unit ): Unit = {
84+ val dummyName = " x_x_x"
85+ val vals = typeStringss.flatten.zipWithIndex.map{case (s, x)=> s " val ${dummyName}$x: $s = ??? " }.mkString(" \n " )
86+ val gatheredSource = s " ${source}\n object A $dummyName { $vals} "
87+ checkCompile(" frontend" , gatheredSource) {
88+ (tree, context) =>
89+ implicit val ctx = context
90+ val findValDef : (List [tpd.ValDef ], tpd.Tree ) => List [tpd.ValDef ] =
91+ (acc , tree) => { tree match {
92+ case t : tpd.ValDef if t.name.startsWith(dummyName) => t :: acc
93+ case _ => acc
94+ }
95+ }
96+ val d = new tpd.DeepFolder [List [tpd.ValDef ]](findValDef).foldOver(Nil , tree)
97+ val tpes = d.map(_.tpe.widen).reverse
98+ val tpess = typeStringss.foldLeft[(List [Type ], List [List [Type ]])]((tpes, Nil )) {
99+ case ((rest, result), typeStrings) =>
100+ val (prefix, suffix) = rest.splitAt(typeStrings.length)
101+ (suffix, prefix :: result)
102+ }._2.reverse
103+ assertion(tpess, context)
104+ }
105+ }
106+
78107 def methType (names : String * )(paramTypes : Type * )(resultType : Type = defn.UnitType ) =
79108 MethodType (names.toList map (_.toTermName), paramTypes.toList, resultType)
80109}
0 commit comments