Skip to content

Commit e2a4e64

Browse files
authored
Merge pull request #7453 from dotty-staging/fix-#6938
Fix #6938: Expand tuples when synthesizing given names
2 parents aebd672 + 21deedf commit e2a4e64

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ object desugar {
963963
case Some(DefDef(name, _, (vparam :: _) :: _, _, _)) =>
964964
s"${name}_of_${inventTypeName(vparam.tpt)}"
965965
case _ =>
966-
ctx.error(i"anonymous instance must have `as` part or must define at least one extension method", impl.sourcePos)
966+
ctx.error(i"anonymous instance must implement a type or have at least one extension method", impl.sourcePos)
967967
nme.ERROR.toString
968968
}
969969
else
@@ -986,7 +986,7 @@ object desugar {
986986
case tree: LambdaTypeTree =>
987987
apply(x, tree.body)
988988
case tree: Tuple =>
989-
if (followArgs) extractArgs(tree.trees) else "Tuple"
989+
extractArgs(tree.trees)
990990
case tree: Function if tree.args.nonEmpty =>
991991
if (followArgs) s"${extractArgs(tree.args)}_to_${apply("", tree.body)}" else "Function"
992992
case _ => foldOver(x, tree)

docs/docs/reference/contextual/delegates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ given Ord[Int] { ... }
4545
given [T](given Ord[T]): Ord[List[T]] { ... }
4646
```
4747
If the name of a given is missing, the compiler will synthesize a name from
48-
the type(s) in the `as` clause.
48+
the implemented type(s).
4949

5050
## Alias Givens
5151

docs/docs/reference/contextual/relationship-implicits.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ The synthesized type names are formed from
5959
- the simple name(s) of the implemented type(s), leaving out any prefixes,
6060
- the simple name(s) of the toplevel argument type constructors to these types.
6161

62+
Tuples are treated as transparent, i.e. a type `F[(X, Y)]` would get the synthesized name
63+
`F_X_Y`. Directly implemented function types `A => B` are represented as `A_to_B`. Function types used as arguments to other type constructors are represented as `Function`.
64+
6265
Anonymous given instances that define extension methods without also implementing a type
6366
get their name from the name of the first extension method and the toplevel type
6467
constructor of its first parameter. For example, the given instance

tests/pos/i6938.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait Foo[T]
2+
object Foo with
3+
given [T]: Foo[Tuple1[T]]
4+
given [T, U]: Foo[(T, U)]
5+
given [T, U, V]: Foo[(T, U, V)]

0 commit comments

Comments
 (0)