Skip to content

Commit

Permalink
Try to fix the error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
tarao committed Dec 25, 2023
1 parent 79c5745 commit 26905de
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions docs/advanced/generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,16 @@ You may think that you can define a method to concatenate two generic records by
`Concat` but it doesn't work in a simple way.

```scala mdoc:fail
def concat[R1 <: %, R2 <: %, RR <: %](r1: R1, r2: R2)(using
Concat.Aux[R1, R2, RR],
): RR = r1 ++ r2
def concat[R1 <: %, R2 <: %, RR <: %](r1: R1, r2: R2)(using Concat.Aux[R1, R2, RR]): RR =
r1 ++ r2
```

The problem is that the right-hand-side argument type of `++` is restricted to be a
concrete type for type safety. In this case, defining an inline method makes it work.

```scala mdoc:mline
inline def concat[R1 <: %, R2 <: %, RR <: %](r1: R1, r2: R2)(using
Concat.Aux[R1, R2, RR],
): RR = r1 ++ r2
inline def concat[R1 <: %, R2 <: %, RR <: %](r1: R1, r2: R2)(using Concat.Aux[R1, R2, RR]): RR =
r1 ++ r2

concat(%(name = "tarao"), %(age = 3))
```

0 comments on commit 26905de

Please sign in to comment.