Skip to content

Commit 116c878

Browse files
committed
Add explanation for @superTrait annotation to docs
1 parent 0a148c3 commit 116c878

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ trait ConstraintHandling[AbstractContext] {
300300
* (i.e. `inst.widenSingletons <:< bound` succeeds with satisfiable constraint)
301301
* 2. If `inst` is a union type, approximate the union type from above by an intersection
302302
* of all common base types, provided the result is a subtype of `bound`.
303-
* 3. If `inst` an intersection such that some operands are super trait instances
303+
* 3. If `inst` is an intersection such that some operands are super trait instances
304304
* and others are not, replace as many super trait instances as possible with Any
305305
* as long as the result is still a subtype of `bound`. But fall back to the
306306
* original type if the resulting widened type is a supertype of all dropped

compiler/src/dotty/tools/dotc/core/Definitions.scala

+2
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,8 @@ class Definitions {
13101310

13111311
@tu lazy val assumedSuperTraits =
13121312
Set(ComparableClass, ProductClass, SerializableClass,
1313+
// add these for now, until we had a chance to retrofit 2.13 stdlib
1314+
// we should do a more through sweep through it then.
13131315
ctx.requiredClass("scala.collection.SortedOps"),
13141316
ctx.requiredClass("scala.collection.StrictOptimizedSortedSetOps"),
13151317
ctx.requiredClass("scala.collection.generic.DefaultSerializable"),

docs/docs/reference/other-new-features/super-traits.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,24 @@ are treated automatically as super traits. Other traits can be turned into super
4343
Every trait can be declared as a super trait. Typically super traits are traits that influence the implementation of inheriting classes and traits and that are not usually used as types by themselves. Two examples from the
4444
standard collection library:
4545

46-
- `IterableLike`, which provides method implementations for an `Iterable`
47-
- `IndexedSeqOptimized`, which optimises some of these implementations for
46+
- `IterableOps`, which provides method implementations for an `Iterable`
47+
- `StrictOptimizedSeqOps`, which optimises some of these implementations for
4848
sequences with efficient indexing.
4949

5050
Generally, any trait that is extended recursively is a good candidate to be
5151
declared a super trait.
5252

53+
### Retro-Fitting Scala 2 Libraries
54+
55+
To allow cross-building between Scala 2 and 3, super traits can also be
56+
introduced by adding the `@superTrait` annotation, which is defined in package `scala.annotation`. Example:
57+
```scala
58+
import scala.annotation.superTrait
59+
60+
@superTrait trait StrictOptimizedSeqOps[+A, +CC[_], +C] ...
61+
```
62+
The `@superTrait` annotation will be deprecated and removed in some later version of Scala when cross-building with Scala 2 will no longer be a concern.
63+
5364
### Rules for Inference
5465

5566
Super traits can be given as explicit types as usual. But they are often elided when types are inferred. Roughly, the rules for type inference say that super traits are dropped from intersections where possible.

0 commit comments

Comments
 (0)