Skip to content

Commit e26f867

Browse files
committed
Add documentation on inline given instances
1 parent b0929f2 commit e26f867

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ object desugar {
810810
}
811811
}
812812
if mods.isAllOf(Given | Inline | Transparent) then
813-
report.error("inline non-alias given cannot be trasparent", cdef)
813+
report.error("inline given instances cannot be trasparent", cdef)
814814
val classMods = if mods.is(Given) then mods &~ (Inline | Transparent) | Synthetic else mods
815815
cpy.TypeDef(cdef: TypeDef)(
816816
name = className,

docs/docs/reference/contextual/givens.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ transparent inline given mkAnnotations[A, T]: Annotations[A, T] = ${
100100

101101
Since `mkAnnotations` is `transparent`, the type of an application is the type of its right-hand side, which can be a proper subtype of the declared result type `Annotations[A, T]`.
102102

103+
Given instances can have the `inline` but not `transparent` modifiers as their type is already known from the signature.
104+
Example:
105+
106+
```scala
107+
trait Show[T] {
108+
inline def show(x: T): String
109+
}
110+
111+
inline given Show[Foo] with {
112+
/*transparent*/ inline def show(x: Foo): String = ${ ... }
113+
}
114+
```
115+
Note that the inline methods within the given instances may be `transparent`.
116+
117+
103118
## Pattern-Bound Given Instances
104119

105120
Given instances can also appear in patterns. Example:

0 commit comments

Comments
 (0)