Skip to content

Fix #6938: Expand tuples when synthesizing given names #7453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ object desugar {
case Some(DefDef(name, _, (vparam :: _) :: _, _, _)) =>
s"${name}_of_${inventTypeName(vparam.tpt)}"
case _ =>
ctx.error(i"anonymous instance must have `as` part or must define at least one extension method", impl.sourcePos)
ctx.error(i"anonymous instance must implement a type or have at least one extension method", impl.sourcePos)
nme.ERROR.toString
}
else
Expand All @@ -986,7 +986,7 @@ object desugar {
case tree: LambdaTypeTree =>
apply(x, tree.body)
case tree: Tuple =>
if (followArgs) extractArgs(tree.trees) else "Tuple"
extractArgs(tree.trees)
case tree: Function if tree.args.nonEmpty =>
if (followArgs) s"${extractArgs(tree.args)}_to_${apply("", tree.body)}" else "Function"
case _ => foldOver(x, tree)
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/contextual/delegates.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ given Ord[Int] { ... }
given [T](given Ord[T]): Ord[List[T]] { ... }
```
If the name of a given is missing, the compiler will synthesize a name from
the type(s) in the `as` clause.
the implemented type(s).

## Alias Givens

Expand Down
3 changes: 3 additions & 0 deletions docs/docs/reference/contextual/relationship-implicits.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ The synthesized type names are formed from
- the simple name(s) of the implemented type(s), leaving out any prefixes,
- the simple name(s) of the toplevel argument type constructors to these types.

Tuples are treated as transparent, i.e. a type `F[(X, Y)]` would get the synthesized name
`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`.

Anonymous given instances that define extension methods without also implementing a type
get their name from the name of the first extension method and the toplevel type
constructor of its first parameter. For example, the given instance
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i6938.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait Foo[T]
object Foo with
given [T]: Foo[Tuple1[T]]
given [T, U]: Foo[(T, U)]
given [T, U, V]: Foo[(T, U, V)]