You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/other-new-features/trait-parameters.md
+11-2Lines changed: 11 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -26,12 +26,14 @@ class D extends C, Greeting("Bill") // error: parameter passed twice
26
26
Should this print "Bob" or "Bill"? In fact this program is illegal,
27
27
because it violates the second rule of the following for trait parameters:
28
28
29
-
1. If a class `C` extends a parameterized trait `T`, and its superclass does not, `C`_must_ pass arguments to `T`.
29
+
1. If a class `C`directly extends a parameterized trait `T`, and its superclass does not, `C`_must_ pass arguments to `T`.
30
30
31
-
2. If a class `C` extends a parameterized trait `T`, and its superclass does as well, `C`_must not_ pass arguments to `T`.
31
+
2. If a class `C`directly or indirectly extends a parameterized trait `T`, and its superclass does as well, `C`_must not_ pass arguments to `T`.
32
32
33
33
3. Traits must never pass arguments to parent traits.
34
34
35
+
4. If a class `C` extends a parameterized trait `T` only indirectly, and its superclass does not extend `T`, then all parameters of `T` must be defined via overrides.
36
+
35
37
Here's a trait extending the parameterized trait `Greeting`.
36
38
37
39
```scala
@@ -51,6 +53,13 @@ The correct way to write `E` is to extend both `Greeting` and
51
53
```scala
52
54
classEextendsGreeting("Bob"), FormalGreeting
53
55
```
56
+
Alternatively, a class could also define the `name` parameter of `Greeting` using
0 commit comments