@@ -6,7 +6,7 @@ disqus: true
6
6
7
7
__ Dmitry Petrashko__
8
8
9
- __ first submitted 13 February 2017__
9
+ __ first submitted 13 January 2017__
10
10
11
11
## Introduction ##
12
12
@@ -19,7 +19,15 @@ As long as signatures of methods in source is not changed, `@binaryCompatible` a
19
19
will be compatible across major version of Scala.
20
20
21
21
## Use Cases
22
- Dotty currently uses java defined interfaces as public API for SBT in order to ensure binary compatibility.
22
+ In case there's a need to develop an API that will be used by clients compiled using different major versions of Scala,
23
+ the current approach is to either develop them in Java or to use best guess to restrict what Scala features should be used.
24
+ There's also a different approach which is used by SBT: instead of publishing a binary ` compiler-interface ` , sources are published instead
25
+ that would be locally compiled.
26
+
27
+ There's also a use-case of defining a class which is supposed to be also used from Java.
28
+ ` @binaryCompatible ` will ensure that there are no not-expected methods that would show up in members of a class or an interface.
29
+
30
+ Dotty currently uses java defined interfaces as public API for IntelliJ in order to ensure binary compatibility.
23
31
These interfaces can be replaced by ` @binaryCompatible ` annotated traits to reach the same goal.
24
32
25
33
## Design Guidelines
@@ -55,7 +63,6 @@ trait AbstractFile {
55
63
56
64
@ binaryCompatible
57
65
trait SourceFile extends AbstractFile {
58
- /** @return The content of this file as seen by the compiler. */
59
66
def content (): Array [Char ]
60
67
}
61
68
@@ -75,13 +82,22 @@ object Diagnostic {
75
82
@ static final val INFO : Int = 0
76
83
}
77
84
85
+ @ binaryCompatible
86
+ class FeaturesInBodies {
87
+ def apiMethod : Int = {
88
+ // as body of the method isn't part of the public interface, one can use all features of Scala here.
89
+ lazy val result = 0 // while lazy vals are prohibited in the class, they are allowed in the bodies of methods
90
+ result
91
+ }
92
+ }
78
93
{% endhighlight % }
79
94
```
80
95
81
96
## Features that will fail compilation with ` @binaryCompatible `
82
97
The features listed below have complex encodings that may change in future versions. We prefer not to compromise on them.
83
98
Most of those features can be simulated in a binary compatible way by writing a verbose re-impelemtation
84
99
which won't rely on desugaring performed inside compiler.
100
+ Note that while those features are prohibited in the public API, they can be safely used inside bodies of the methods.
85
101
86
102
- public fields. Can be simulated by explicitly defining public getters and setters that access a private field;
87
103
- lazy vals. Can be simulated by explicitly writing an implementation in source;
0 commit comments