@@ -505,7 +505,7 @@ object desugar {
505
505
val clsTmpl = cpy.Template (tmpl)(self = clsSelf, body = tmpl.body)
506
506
val cls = TypeDef (clsName, clsTmpl)
507
507
.withMods(mods.toTypeFlags & RetainedModuleClassFlags | ModuleClassCreationFlags )
508
- Thicket (modul, classDef(cls))
508
+ Thicket (modul, classDef(cls).withPos(mdef.pos) )
509
509
}
510
510
}
511
511
@@ -516,7 +516,7 @@ object desugar {
516
516
def patDef (pdef : PatDef )(implicit ctx : Context ): Tree = {
517
517
val PatDef (mods, pats, tpt, rhs) = pdef
518
518
val pats1 = if (tpt.isEmpty) pats else pats map (Typed (_, tpt))
519
- flatTree(pats1 map (makePatDef(mods, _, rhs)))
519
+ flatTree(pats1 map (makePatDef(pdef, mods, _, rhs)))
520
520
}
521
521
522
522
/** If `pat` is a variable pattern,
@@ -534,9 +534,9 @@ object desugar {
534
534
* If the original pattern variable carries a type annotation, so does the corresponding
535
535
* ValDef or DefDef.
536
536
*/
537
- def makePatDef (mods : Modifiers , pat : Tree , rhs : Tree )(implicit ctx : Context ): Tree = pat match {
537
+ def makePatDef (original : Tree , mods : Modifiers , pat : Tree , rhs : Tree )(implicit ctx : Context ): Tree = pat match {
538
538
case VarPattern (named, tpt) =>
539
- derivedValDef(named, tpt, rhs, mods)
539
+ derivedValDef(original, named, tpt, rhs, mods)
540
540
case _ =>
541
541
val rhsUnchecked = makeAnnotated(defn.UncheckedAnnot , rhs)
542
542
val vars = getVariables(pat)
@@ -553,7 +553,7 @@ object desugar {
553
553
case Nil =>
554
554
matchExpr
555
555
case (named, tpt) :: Nil =>
556
- derivedValDef(named, tpt, matchExpr, mods)
556
+ derivedValDef(original, named, tpt, matchExpr, mods)
557
557
case _ =>
558
558
val tmpName = ctx.freshName().toTermName
559
559
val patMods = mods & (AccessFlags | Lazy ) | Synthetic
@@ -564,8 +564,8 @@ object desugar {
564
564
val restDefs =
565
565
for (((named, tpt), n) <- vars.zipWithIndex)
566
566
yield
567
- if (mods is Lazy ) derivedDefDef(named, tpt, selector(n), mods &~ Lazy )
568
- else derivedValDef(named, tpt, selector(n), mods)
567
+ if (mods is Lazy ) derivedDefDef(original, named, tpt, selector(n), mods &~ Lazy )
568
+ else derivedValDef(original, named, tpt, selector(n), mods)
569
569
flatTree(firstDef :: restDefs)
570
570
}
571
571
}
@@ -632,7 +632,7 @@ object desugar {
632
632
val selector = makeTuple(params.map(p => Ident (p.name)))
633
633
634
634
if (unchecked)
635
- Function (params, Match (Annotated (New (ref(defn.UncheckedAnnotType )), selector ), cases))
635
+ Function (params, Match (Annotated (selector, New (ref(defn.UncheckedAnnotType ))), cases))
636
636
else
637
637
Function (params, Match (selector, cases))
638
638
}
@@ -661,16 +661,20 @@ object desugar {
661
661
* tree @cls
662
662
*/
663
663
def makeAnnotated (cls : Symbol , tree : Tree )(implicit ctx : Context ) =
664
- Annotated (untpd.New (untpd.TypeTree (cls.typeRef), Nil ), tree )
664
+ Annotated (tree, untpd.New (untpd.TypeTree (cls.typeRef), Nil ))
665
665
666
- private def derivedValDef (named : NameTree , tpt : Tree , rhs : Tree , mods : Modifiers )(implicit ctx : Context ) = {
667
- val vdef = ValDef (named.name.asTermName, tpt, rhs).withMods(mods).withPos(named.pos)
666
+ private def derivedValDef (original : Tree , named : NameTree , tpt : Tree , rhs : Tree , mods : Modifiers )(implicit ctx : Context ) = {
667
+ val vdef = ValDef (named.name.asTermName, tpt, rhs)
668
+ .withMods(mods)
669
+ .withPos(original.pos.withPoint(named.pos.start))
668
670
val mayNeedSetter = valDef(vdef)
669
671
mayNeedSetter
670
672
}
671
673
672
- private def derivedDefDef (named : NameTree , tpt : Tree , rhs : Tree , mods : Modifiers ) =
673
- DefDef (named.name.asTermName, Nil , Nil , tpt, rhs).withMods(mods).withPos(named.pos)
674
+ private def derivedDefDef (original : Tree , named : NameTree , tpt : Tree , rhs : Tree , mods : Modifiers ) =
675
+ DefDef (named.name.asTermName, Nil , Nil , tpt, rhs)
676
+ .withMods(mods)
677
+ .withPos(original.pos.withPoint(named.pos.start))
674
678
675
679
/** Main desugaring method */
676
680
def apply (tree : Tree )(implicit ctx : Context ): Tree = {
@@ -760,7 +764,7 @@ object desugar {
760
764
*/
761
765
def makeLambda (pat : Tree , body : Tree ): Tree = pat match {
762
766
case VarPattern (named, tpt) =>
763
- Function (derivedValDef(named, tpt, EmptyTree , Modifiers (Param )) :: Nil , body)
767
+ Function (derivedValDef(pat, named, tpt, EmptyTree , Modifiers (Param )) :: Nil , body)
764
768
case _ =>
765
769
makeCaseLambda(CaseDef (pat, EmptyTree , body) :: Nil , unchecked = false )
766
770
}
@@ -863,7 +867,7 @@ object desugar {
863
867
val rhss = valeqs map { case GenAlias (_, rhs) => rhs }
864
868
val (defpat0, id0) = makeIdPat(pat)
865
869
val (defpats, ids) = (pats map makeIdPat).unzip
866
- val pdefs = (defpats, rhss).zipped map (makePatDef(Modifiers (), _, _))
870
+ val pdefs = (valeqs, defpats, rhss).zipped. map(makePatDef(_, Modifiers (), _, _))
867
871
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom (defpat0, rhs) :: Nil , Block (pdefs, makeTuple(id0 :: ids)))
868
872
val allpats = pat :: pats
869
873
val vfrom1 = new IrrefutableGenFrom (makeTuple(allpats), rhs1)
@@ -885,7 +889,15 @@ object desugar {
885
889
Apply (
886
890
ref(defn.SymbolClass .companionModule.termRef),
887
891
Literal (Constant (str)) :: Nil )
888
- case InterpolatedString (id, strs, elems) =>
892
+ case InterpolatedString (id, segments) =>
893
+ val strs = segments map {
894
+ case ts : Thicket => ts.trees.head
895
+ case t => t
896
+ }
897
+ val elems = segments flatMap {
898
+ case ts : Thicket => ts.trees.tail
899
+ case t => Nil
900
+ }
889
901
Apply (Select (Apply (Ident (nme.StringContext ), strs), id), elems)
890
902
case InfixOp (l, op, r) =>
891
903
if (ctx.mode is Mode .Type )
@@ -900,8 +912,8 @@ object desugar {
900
912
if ((ctx.mode is Mode .Type ) && op == nme.raw.STAR ) {
901
913
val seqType = if (ctx.compilationUnit.isJava) defn.ArrayType else defn.SeqType
902
914
Annotated (
903
- New (ref(defn. RepeatedAnnotType ), Nil :: Nil ),
904
- AppliedTypeTree (ref(seqType ), t ))
915
+ AppliedTypeTree (ref(seqType ), t ),
916
+ New (ref(defn. RepeatedAnnotType ), Nil :: Nil ))
905
917
} else {
906
918
assert(ctx.mode.isExpr || ctx.reporter.hasErrors, ctx.mode)
907
919
Select (t, op)
@@ -946,7 +958,7 @@ object desugar {
946
958
makeFor(nme.map, nme.flatMap, enums, body) orElse tree
947
959
case PatDef (mods, pats, tpt, rhs) =>
948
960
val pats1 = if (tpt.isEmpty) pats else pats map (Typed (_, tpt))
949
- flatTree(pats1 map (makePatDef(mods, _, rhs)))
961
+ flatTree(pats1 map (makePatDef(tree, mods, _, rhs)))
950
962
case ParsedTry (body, handler, finalizer) =>
951
963
handler match {
952
964
case Match (EmptyTree , cases) => Try (body, cases, finalizer)
@@ -1048,10 +1060,10 @@ object desugar {
1048
1060
case Alternative (trees) =>
1049
1061
for (tree <- trees; (vble, _) <- getVariables(tree))
1050
1062
ctx.error(" illegal variable in pattern alternative" , vble.pos)
1051
- case Annotated (annot, arg ) =>
1063
+ case Annotated (arg, _ ) =>
1052
1064
collect(arg)
1053
- case InterpolatedString (_, _, elems ) =>
1054
- elems foreach collect
1065
+ case InterpolatedString (_, segments ) =>
1066
+ segments foreach collect
1055
1067
case InfixOp (left, _, right) =>
1056
1068
collect(left)
1057
1069
collect(right)
0 commit comments