Skip to content

Commit 231a559

Browse files
authored
Merge pull request #4 from satorg/main
Adds some docs to the repo
2 parents 1fb73d1 + 4890fc4 commit 231a559

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Early Semantic Versioning](https://docs.scala-lang.org/overviews/core/binary-compatibility-for-library-authors.html#recommended-versioning-scheme) in addition to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.0] - 2022-11-04
9+
10+
### Added
11+
- Specialized `@nowarn` annotations: `@nowarn2`, `@nowarn212`, `@nowarn213`, `@nowarn3`.
12+
- Compatibility `@unused` annotation.
13+
14+
### Changed
15+
- **README.md**: added description and documentation.

README.md

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,89 @@
1-
# scalac-compat
1+
# scalac-compat
2+
3+
*scalac-compat* is a <sub>micro</sub>library containing a set of lightweight tools designed to tackle mismatches between different Scala compiler versions in cross-build projects.
4+
5+
Currently it consists of a single module *scalac-compat-annotation*.
6+
7+
## scalac-compat-annotation
8+
9+
The module contains Scala version specific annotations that can help to tune a build in cases when different Scala compiler versions may treat same standard annotations differently.
10+
11+
### Usage
12+
13+
The module is published for Scala 2.12.x, 2.13.x and 3.2.x:
14+
```scala
15+
// sbt
16+
"org.typelevel" %% "scalac-compat-annotation" % "{{MODULE_VERSION}}"
17+
18+
// mill
19+
ivy"org.typelevel::scalac-compat-annotation:{{MODULE_VERSION}}"
20+
21+
// Scala CLI
22+
//> using lib "org.typelevel::scalac-compat-annotation:{{MODULE_VERSION}}"
23+
```
24+
Then import the module annotations:
25+
```scala
26+
import org.typelevel.scalaccompat.annotation._
27+
```
28+
29+
#### `@nowarn` annotation specializations
30+
31+
There are a set of specializations defined for `@scala.annotation.nowarn` that either redirect to the standard annotation or to a no-op annotation depending on a particular Scala version:
32+
33+
| Scala<br>version | `@nowarn2` | `@nowarn212` | `@nowarn213` | `@nowarn3` |
34+
| ---- | ---------- | ------------ | ------------ | ---------- |
35+
| 2.12 | `@nowarn` | `@nowarn` | no-op | no-op |
36+
| 2.13 | `@nowarn` | no-op | `@nowarn` | no-op |
37+
| 3 | no-op | no-op | no-op | `@nowarn` |
38+
39+
##### Example
40+
41+
Consider a case when someone has to deal with `scala.collection.Stream` in a cross-build project. `Stream` is deprecated since Scala v2.13. However, simply applying `@nowarn("cat=deprecation")` to methods that attempt to reference to `Stream` may lead to another warning on Scala version prior to v2.13:
42+
```
43+
@nowarn annotation does not suppress any warnings
44+
```
45+
Thus the specialized `@nowarn` annotations can come in handy here:
46+
```scala
47+
import org.typelevel.scalaccompat.annotation._
48+
49+
@nowarn213("cat=deprecation")
50+
@nowarn3("cat=deprecation")
51+
def reinventTheWheel: Stream[Int] = {
52+
Stream
53+
.iterate((1, 1)) { case (a2, a1) => (a1, a2 + a1) }
54+
.map(_._1)
55+
}
56+
```
57+
58+
#### `@unused` compatibility annotation
59+
60+
The `@scala.annotation.unused` annotation was introduced since Scala v2.13.x and does not exists in previous versions of Scala library. The compatibility `@org.typelevel.scalaccompat.annotation.unused` annotation simply redirects to the `@scala.annotation.unused` on versions where it exists while mimics the same behavior with `@scala.annotation.nowarn` for Scala v2.12.x:
61+
62+
| Scala<br>version | `@scalaccompat.annotation.unused`<br>redirects to |
63+
| ---- | ---------------------------------------- |
64+
| 2.12 | `@scala.annotation.nowarn("cat=unused")` |
65+
| 2.13 | `@scala.annotation.unused` |
66+
| 3 | `@scala.annotation.unused` |
67+
68+
##### Example
69+
70+
```scala
71+
// Notice that there is no need to import `scala.annotation.unused`.
72+
import org.typelevel.scalaccompat.annotation._
73+
74+
// Compiles on all supported Scala versions.
75+
def testUnusedParam(name: String, @unused unusedParam: String): Unit = {
76+
// The `unusedParam` is not used withing the body.
77+
println(s"Hello, $name")
78+
}
79+
```
80+
81+
See more examples in **./annotation/src/test**
82+
83+
## Conduct
84+
85+
Participants are expected to follow the [Scala Code of Conduct](https://www.scala-lang.org/conduct/) while discussing the project on GitHub and any other venues associated with the project. See the [organizational Code of Conduct](https://github.com/typelevel/.github/blob/main/CODE_OF_CONDUCT.md) for more details.
86+
87+
## License
88+
89+
All code in this repository is licensed under the Apache License, Version 2.0. See [LICENSE](./LICENSE).

0 commit comments

Comments
 (0)