@@ -771,7 +771,7 @@ object desugar {
771
771
(elimTypeDefs.transform(tree), bindingsBuf.toList)
772
772
}
773
773
774
- /** augment <type-pattern> <params> extends <parents> { <body>} }
774
+ /** augment [<id> @] <type-pattern> <params> extends <parents> { <body>} }
775
775
* ->
776
776
* implicit class <deconame> <type-params> ($this: <decorated>) <combined-params>
777
777
* extends <parents> { <body1> }
@@ -781,7 +781,8 @@ object desugar {
781
781
* (<decorated>, <type-params0>) = decomposeTypePattern(<type-pattern>)
782
782
* (<type-params>, <evidence-params>) = desugarTypeBindings(<type-params0>)
783
783
* <combined-params> = <params> concatenated with <evidence-params> in one clause
784
- * <deconame> = <from>To<parent>_in_<location>$$<n> where <parent> is first extended class name
784
+ * <deconame> = <id> if there is a `id @` binding
785
+ * = <from>To<parent>_in_<location>$$<n> where <parent> is first extended class name
785
786
*
786
787
* = <from>Augmentation_in_<location>$$<n> if no such <parent> exists
787
788
* <from> = underlying type name of <decorated>
@@ -791,7 +792,7 @@ object desugar {
791
792
*
792
793
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
793
794
*
794
- * augment <type-pattern> <params> { <body> }
795
+ * augment [<id> @] <type-pattern> <params> { <body> }
795
796
* ->
796
797
* implicit class <deconame> <type-params> ($this: <decorated>)
797
798
* extends AnyVal { <body2> }
@@ -802,22 +803,26 @@ object desugar {
802
803
* <deconame>, <type-params> are as above.
803
804
*/
804
805
def augmentation (tree : Augment )(implicit ctx : Context ): Tree = {
805
- val Augment (augmented, impl) = tree
806
+ val Augment (id, augmented, impl) = tree
806
807
val isSimpleExtension =
807
808
impl.parents.isEmpty &&
808
809
impl.self.isEmpty &&
809
810
impl.body.forall(_.isInstanceOf [DefDef ])
810
811
val (decorated, bindings) = decomposeTypePattern(augmented)
811
812
val (typeParams, evidenceParams) =
812
813
desugarTypeBindings(bindings, forPrimaryConstructor = ! isSimpleExtension)
813
- val decoName = {
814
- def clsName (tree : Tree ): String = leadingName(" " , tree)
815
- val fromName = clsName(augmented)
816
- val toName = impl.parents match {
817
- case parent :: _ if ! clsName(parent).isEmpty => " To" + clsName(parent)
818
- case _ => str.Augmentation
819
- }
820
- s " ${fromName}${toName}_in_ ${ctx.owner.topLevelClass.flatName}"
814
+ val decoName = id match {
815
+ case Ident (name) =>
816
+ name.asTypeName
817
+ case EmptyTree =>
818
+ def clsName (tree : Tree ): String = leadingName(" " , tree)
819
+ val fromName = clsName(augmented)
820
+ val toName = impl.parents match {
821
+ case parent :: _ if ! clsName(parent).isEmpty => " To" + clsName(parent)
822
+ case _ => " Augmentation"
823
+ }
824
+ val prefix = s " ${fromName}${toName}_in_ ${ctx.owner.topLevelClass.flatName}"
825
+ UniqueName .fresh(prefix.toTermName).toTypeName
821
826
}
822
827
823
828
val firstParam = ValDef (nme.SELF , decorated, EmptyTree ).withFlags(Private | Local | ParamAccessor )
@@ -842,7 +847,7 @@ object desugar {
842
847
constr1 = addEvidenceParams(constr1, evidenceParams)
843
848
844
849
val icls =
845
- TypeDef (UniqueName .fresh( decoName.toTermName).toTypeName ,
850
+ TypeDef (decoName,
846
851
cpy.Template (impl)(constr = constr1, parents = parents1, body = body1))
847
852
.withFlags(Implicit )
848
853
desugr.println(i " desugar $augmented --> $icls" )
0 commit comments