@@ -771,7 +771,7 @@ object desugar {
771771 (elimTypeDefs.transform(tree), bindingsBuf.toList)
772772 }
773773
774- /** augment <type-pattern> <params> extends <parents> { <body>} }
774+ /** augment [<id> @] <type-pattern> <params> extends <parents> { <body>} }
775775 * ->
776776 * implicit class <deconame> <type-params> ($this: <decorated>) <combined-params>
777777 * extends <parents> { <body1> }
@@ -781,7 +781,8 @@ object desugar {
781781 * (<decorated>, <type-params0>) = decomposeTypePattern(<type-pattern>)
782782 * (<type-params>, <evidence-params>) = desugarTypeBindings(<type-params0>)
783783 * <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
785786 *
786787 * = <from>Augmentation_in_<location>$$<n> if no such <parent> exists
787788 * <from> = underlying type name of <decorated>
@@ -791,7 +792,7 @@ object desugar {
791792 *
792793 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
793794 *
794- * augment <type-pattern> <params> { <body> }
795+ * augment [<id> @] <type-pattern> <params> { <body> }
795796 * ->
796797 * implicit class <deconame> <type-params> ($this: <decorated>)
797798 * extends AnyVal { <body2> }
@@ -802,22 +803,26 @@ object desugar {
802803 * <deconame>, <type-params> are as above.
803804 */
804805 def augmentation (tree : Augment )(implicit ctx : Context ): Tree = {
805- val Augment (augmented, impl) = tree
806+ val Augment (id, augmented, impl) = tree
806807 val isSimpleExtension =
807808 impl.parents.isEmpty &&
808809 impl.self.isEmpty &&
809810 impl.body.forall(_.isInstanceOf [DefDef ])
810811 val (decorated, bindings) = decomposeTypePattern(augmented)
811812 val (typeParams, evidenceParams) =
812813 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
821826 }
822827
823828 val firstParam = ValDef (nme.SELF , decorated, EmptyTree ).withFlags(Private | Local | ParamAccessor )
@@ -842,7 +847,7 @@ object desugar {
842847 constr1 = addEvidenceParams(constr1, evidenceParams)
843848
844849 val icls =
845- TypeDef (UniqueName .fresh( decoName.toTermName).toTypeName ,
850+ TypeDef (decoName,
846851 cpy.Template (impl)(constr = constr1, parents = parents1, body = body1))
847852 .withFlags(Implicit )
848853 desugr.println(i " desugar $augmented --> $icls" )
0 commit comments