@@ -580,82 +580,23 @@ trait Implicits { self: Typer =>
580
580
}
581
581
582
582
def synthesizedTypeTag (formal : Type ): Tree = formal.argInfos match {
583
- case tpe :: Nil =>
584
- var ok = true
585
-
586
- def toParamSyms (tpe : LambdaType ): List [Symbol { type ThisName = tpe.ThisName }] =
587
- (tpe.paramNames, tpe.paramInfos).zipped.map((name, bounds) =>
588
- ctx.newSymbol(ctx.owner, name, Param , bounds))
589
-
590
- def toTreeAndDefs (tpe : Type ): (List [TypeSymbol ], List [List [TermSymbol ]], Tree ) = tpe match {
591
- case tpe : TypeLambda =>
592
- val tsyms = toParamSyms(tpe)
593
- val (Nil , vsymss, result) = toTreeAndDefs(tpe.resultType.substParams(tpe, tsyms.map(_.typeRef)))
594
- (tsyms, vsymss, result)
595
- case tpe : TermLambda =>
596
- val vsyms = toParamSyms(tpe)
597
- val (Nil , vsymss, result) = toTreeAndDefs(tpe.resultType.substParams(tpe, vsyms.map(_.termRef)))
598
- (Nil , vsyms :: vsymss, result)
599
- case _ =>
600
- (Nil , Nil , toTree(tpe))
601
- }
602
-
603
- def refinedToTree (tpe : Type , refinements : List [Tree ], refineCls : ClassSymbol ): Tree = tpe.stripTypeVar match {
604
- case RefinedType (parent, rname, rinfo) =>
605
- val isMethod = rinfo.isInstanceOf [MethodOrPoly ]
606
- val sym = ctx.newSymbol(refineCls, rname, if (isMethod) Method else EmptyFlags , rinfo)
607
- val refinement = rname match {
608
- case rname : TypeName =>
609
- TypeDef (sym.asType)
610
- case rname : TermName =>
611
- if (isMethod) {
612
- val (tparams, vparamss, resTpt) = toTreeAndDefs(rinfo.asInstanceOf [MethodOrPoly ])
613
- DefDef (sym.asTerm, tparams, vparamss, resTpt.tpe, EmptyTree )
614
- }
615
- else ValDef (sym.asTerm)
616
- }
617
- refinedToTree(parent, refinement :: refinements, refineCls)
618
- case _ =>
619
- RefinedTypeTree (toTree(tpe), refinements, refineCls)
620
- }
621
-
622
- def toTree (tpe : Type ): Tree = tpe.stripTypeVar match {
623
- case tpe @ TypeRef (NoPrefix , _) =>
624
- inferImplicit(defn.QuotedTypeType .appliedTo(tpe), EmptyTree , pos) match {
625
- case SearchSuccess (tag, _, _) =>
626
- tag.select(defn.QuotedType_~ )
627
- case _ =>
628
- ok = false
629
- EmptyTree
630
- }
631
- case tpe : NamedType =>
632
- ref(tpe)
633
- case tpe : SingletonType =>
634
- singleton(tpe)
635
- case AppliedType (tycon, args) =>
636
- AppliedTypeTree (toTree(tycon), args.map(toTree))
637
- case AndType (l, r) =>
638
- AndTypeTree (toTree(l), toTree(r))
639
- case OrType (l, r) =>
640
- OrTypeTree (toTree(l), toTree(r))
641
- case tp : HKTypeLambda =>
642
- val tsyms = toParamSyms(tp)
643
- toTree(tp.resType.substParams(tp, tsyms.map(_.typeRef)))
644
- case tpe : RecType =>
645
- refinedToTree(tpe.parent, Nil , ctx.newRefinedClassSymbol())
646
- case tpe : RefinedType =>
647
- refinedToTree(tpe, Nil , ctx.newRefinedClassSymbol())
648
- case TypeAlias (alias) =>
649
- val aliasTree = toTree(alias)
650
- TypeBoundsTree (aliasTree, aliasTree)
651
- case TypeBounds (lo, hi) =>
652
- TypeBoundsTree (toTree(lo), toTree(hi))
653
- case _ =>
654
- EmptyTree
583
+ case arg :: Nil =>
584
+ object bindFreeVars extends TypeMap {
585
+ var ok = true
586
+ def apply (t : Type ) = t match {
587
+ case t @ TypeRef (NoPrefix , _) =>
588
+ inferImplicit(defn.QuotedTypeType .appliedTo(t), EmptyTree , pos) match {
589
+ case SearchSuccess (tag, _, _) if tag.tpe.isStable =>
590
+ tag.tpe.select(defn.QuotedType_~ )
591
+ case _ =>
592
+ ok = false
593
+ t
594
+ }
595
+ case _ => t
596
+ }
655
597
}
656
-
657
- val tag = toTree(tpe)
658
- if (ok) ref(defn.typeQuoteMethod).appliedToTypeTrees(tag :: Nil )
598
+ val tag = bindFreeVars(arg)
599
+ if (bindFreeVars.ok) ref(defn.typeQuoteMethod).appliedToType(tag)
659
600
else EmptyTree
660
601
case _ =>
661
602
EmptyTree
0 commit comments