diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index c515ca94c93c..09688127551f 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -999,12 +999,16 @@ object desugar { case tree: TypeDef => tree.name.toString case tree: AppliedTypeTree if followArgs && tree.args.nonEmpty => s"${apply(x, tree.tpt)}_${extractArgs(tree.args)}" + case InfixOp(left, op, right) => + if followArgs then s"${op.name}_${extractArgs(List(left, right))}" + else op.name.toString case tree: LambdaTypeTree => apply(x, tree.body) case tree: Tuple => extractArgs(tree.trees) case tree: Function if tree.args.nonEmpty => - if (followArgs) s"${extractArgs(tree.args)}_to_${apply("", tree.body)}" else "Function" + if followArgs then s"${extractArgs(tree.args)}_to_${apply("", tree.body)}" + else "Function" case _ => foldOver(x, tree) } else x diff --git a/tests/neg/i10927.scala b/tests/neg/i10927.scala new file mode 100644 index 000000000000..c0842b5dc81a --- /dev/null +++ b/tests/neg/i10927.scala @@ -0,0 +1,23 @@ +trait Transition[From, To] + +infix type ==>[From, To] = Transition[From, To] + +type A = A.type +object A + +type B = B.type +object B + +type C = C.type +object C + +// Compiles +given (A ==> B) = ??? + +// was Compile error +given (A ==> C) = ??? + +given ==>[A, C] = ??? // error: double definition + +given List[A ==> B] = ??? +given List[A ==> C] = ??? // error: double definition diff --git a/tests/pos/i10927.scala b/tests/pos/i10927.scala new file mode 100644 index 000000000000..49a38261eed4 --- /dev/null +++ b/tests/pos/i10927.scala @@ -0,0 +1,18 @@ +trait Transition[From, To] + +infix type ==>[From, To] = Transition[From, To] + +type A = A.type +object A + +type B = B.type +object B + +type C = C.type +object C + +// Compiles +given (A ==> B) = ??? + +// was Compile error +given (A ==> C) = ??? diff --git a/tests/semanticdb/expect/Enums.expect.scala b/tests/semanticdb/expect/Enums.expect.scala index aa8f430e173c..a434d3f777b7 100644 --- a/tests/semanticdb/expect/Enums.expect.scala +++ b/tests/semanticdb/expect/Enums.expect.scala @@ -47,12 +47,12 @@ object Enums/*<-_empty_::Enums.*/: case Refl/*<-_empty_::Enums.`<:<`.Refl#*/[C/*<-_empty_::Enums.`<:<`.Refl#[C]*/]() extends (C/*->_empty_::Enums.`<:<`.Refl#[C]*/ <:_empty_::Enums.`<:<`#*/ C/*->_empty_::Enums.`<:<`.Refl#[C]*/) object <:_empty_::Enums.`<:<`.given_T().[T]*/ <:_empty_::Enums.`<:<`#*/ T/*->_empty_::Enums.`<:<`.given_T().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/() + given [T]: (T <:< T/*<-_empty_::Enums.`<:<`.`given_<:<_T_T`().*//*<-_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*//*->_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*//*->_empty_::Enums.`<:<`#*//*->_empty_::Enums.`<:<`.`given_<:<_T_T`().[T]*/) = Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.apply().*/() extension [A/*<-_empty_::Enums.unwrap().[A]*/, B/*<-_empty_::Enums.unwrap().[B]*/](opt/*<-_empty_::Enums.unwrap().(opt)*/: Option/*->scala::Option#*/[A/*->_empty_::Enums.unwrap().[A]*/]) def unwrap/*<-_empty_::Enums.unwrap().*/(using ev/*<-_empty_::Enums.unwrap().(ev)*/: A/*->_empty_::Enums.unwrap().[A]*/ <:_empty_::Enums.`<:<`#*/ Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]): Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/] = ev/*->_empty_::Enums.unwrap().(ev)*/ match case Refl/*->_empty_::Enums.`<:<`.Refl.*//*->_empty_::Enums.`<:<`.Refl.unapply().*/() => opt/*->_empty_::Enums.unwrap().(opt)*/.flatMap/*->scala::Option#flatMap().*/(identity/*->scala::Predef.identity().*//*->local0*/[Option/*->scala::Option#*/[B/*->_empty_::Enums.unwrap().[B]*/]]) - val some1/*<-_empty_::Enums.some1.*/ = Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1)).unwrap/*->_empty_::Enums.unwrap().*//*->_empty_::Enums.`<:<`.given_T().*/ + val some1/*<-_empty_::Enums.some1.*/ = Some/*->scala::Some.*//*->scala::Some.apply().*/(Some/*->scala::Some.*//*->scala::Some.apply().*/(1)).unwrap/*->_empty_::Enums.unwrap().*//*->_empty_::Enums.`<:<`.`given_<:<_T_T`().*/ enum Planet/*<-_empty_::Enums.Planet#*/(mass/*<-_empty_::Enums.Planet#mass.*/: Double/*->scala::Double#*/, radius/*<-_empty_::Enums.Planet#radius.*/: Double/*->scala::Double#*/) extends Enum/*->java::lang::Enum#*/[Planet/*->_empty_::Enums.Planet#*/]/*->java::lang::Enum#``().*/: private final val G/*<-_empty_::Enums.Planet#G.*/ = 6.67300E-11 diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index c83ab8b3f45f..b4b18b9c8396 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -840,10 +840,10 @@ _empty_/Enums.`<:<`.Refl.toString(). => method toString _empty_/Enums.`<:<`.Refl.unapply(). => method unapply _empty_/Enums.`<:<`.Refl.unapply().(x$1) => param x$1 _empty_/Enums.`<:<`.Refl.unapply().[C] => typeparam C +_empty_/Enums.`<:<`.`given_<:<_T_T`(). => final implicit method given_<:<_T_T +_empty_/Enums.`<:<`.`given_<:<_T_T`().[T] => typeparam T _empty_/Enums.`<:<`.fromOrdinal(). => method fromOrdinal _empty_/Enums.`<:<`.fromOrdinal().(ordinal) => param ordinal -_empty_/Enums.`<:<`.given_T(). => final implicit method given_T -_empty_/Enums.`<:<`.given_T().[T] => typeparam T _empty_/Enums.some1. => val method some1 _empty_/Enums.unwrap(). => method unwrap _empty_/Enums.unwrap().(ev) => implicit param ev @@ -962,11 +962,11 @@ Occurrences: [46:34..46:35): C -> _empty_/Enums.`<:<`.Refl#[C] [46:35..46:35): -> _empty_/Enums.`<:<`#``(). [48:9..48:12): <:< <- _empty_/Enums.`<:<`. -[49:10..49:17): [T]: (T <- _empty_/Enums.`<:<`.given_T(). -[49:11..49:12): T <- _empty_/Enums.`<:<`.given_T().[T] -[49:16..49:17): T -> _empty_/Enums.`<:<`.given_T().[T] +[49:10..49:23): [T]: (T <:< T <- _empty_/Enums.`<:<`.`given_<:<_T_T`(). +[49:11..49:12): T <- _empty_/Enums.`<:<`.`given_<:<_T_T`().[T] +[49:16..49:17): T -> _empty_/Enums.`<:<`.`given_<:<_T_T`().[T] [49:18..49:21): <:< -> _empty_/Enums.`<:<`# -[49:22..49:23): T -> _empty_/Enums.`<:<`.given_T().[T] +[49:22..49:23): T -> _empty_/Enums.`<:<`.`given_<:<_T_T`().[T] [49:27..49:31): Refl -> _empty_/Enums.`<:<`.Refl. [49:31..49:31): -> _empty_/Enums.`<:<`.Refl.apply(). [51:13..51:14): A <- _empty_/Enums.unwrap().[A] @@ -997,7 +997,7 @@ Occurrences: [54:19..54:23): Some -> scala/Some. [54:23..54:23): -> scala/Some.apply(). [54:28..54:34): unwrap -> _empty_/Enums.unwrap(). -[54:34..54:34): -> _empty_/Enums.`<:<`.given_T(). +[54:34..54:34): -> _empty_/Enums.`<:<`.`given_<:<_T_T`(). [56:7..56:13): Planet <- _empty_/Enums.Planet# [56:13..56:13): <- _empty_/Enums.Planet#``(). [56:14..56:18): mass <- _empty_/Enums.Planet#mass.