Skip to content

Commit 9cffd70

Browse files
oderskymichelou
authored andcommitted
Fix name generation for anonymous given of infix types.
Fixes scala#10927
1 parent 2269fc1 commit 9cffd70

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,12 +999,16 @@ object desugar {
999999
case tree: TypeDef => tree.name.toString
10001000
case tree: AppliedTypeTree if followArgs && tree.args.nonEmpty =>
10011001
s"${apply(x, tree.tpt)}_${extractArgs(tree.args)}"
1002+
case InfixOp(left, op, right) =>
1003+
if followArgs then s"${op.name}_${extractArgs(List(left, right))}"
1004+
else op.name.toString
10021005
case tree: LambdaTypeTree =>
10031006
apply(x, tree.body)
10041007
case tree: Tuple =>
10051008
extractArgs(tree.trees)
10061009
case tree: Function if tree.args.nonEmpty =>
1007-
if (followArgs) s"${extractArgs(tree.args)}_to_${apply("", tree.body)}" else "Function"
1010+
if followArgs then s"${extractArgs(tree.args)}_to_${apply("", tree.body)}"
1011+
else "Function"
10081012
case _ => foldOver(x, tree)
10091013
}
10101014
else x

tests/neg/i10927.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
trait Transition[From, To]
2+
3+
infix type ==>[From, To] = Transition[From, To]
4+
5+
type A = A.type
6+
object A
7+
8+
type B = B.type
9+
object B
10+
11+
type C = C.type
12+
object C
13+
14+
// Compiles
15+
given (A ==> B) = ???
16+
17+
// was Compile error
18+
given (A ==> C) = ???
19+
20+
given ==>[A, C] = ??? // error: double definition
21+
22+
given List[A ==> B] = ???
23+
given List[A ==> C] = ??? // error: double definition

tests/pos/i10927.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trait Transition[From, To]
2+
3+
infix type ==>[From, To] = Transition[From, To]
4+
5+
type A = A.type
6+
object A
7+
8+
type B = B.type
9+
object B
10+
11+
type C = C.type
12+
object C
13+
14+
// Compiles
15+
given (A ==> B) = ???
16+
17+
// was Compile error
18+
given (A ==> C) = ???

0 commit comments

Comments
 (0)