forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of the fix for scala#15413 Part of the fix for scala#16983
- Loading branch information
1 parent
847eccc
commit b84e171
Showing
19 changed files
with
304 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
compiler/src/dotty/tools/dotc/transform/BinaryAPIAnnotations.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package dotty.tools.dotc | ||
package transform | ||
|
||
import core._ | ||
import ast.tpd._ | ||
import Contexts._ | ||
import MegaPhase._ | ||
import Annotations._ | ||
import Symbols.defn | ||
import Constants._ | ||
import Types._ | ||
import Symbols.* | ||
import Decorators._ | ||
import Flags._ | ||
import DenotTransformers.SymTransformer | ||
import SymDenotations.SymDenotation | ||
|
||
/** Makes @binaryAPI definitions public */ | ||
class BinaryAPIAnnotations extends MiniPhase with SymTransformer: | ||
|
||
override def phaseName: String = BinaryAPIAnnotations.name | ||
|
||
override def description: String = BinaryAPIAnnotations.description | ||
|
||
def transformSym(d: SymDenotation)(using Context): SymDenotation = | ||
if d.isBinaryAPI then | ||
d.resetFlag(Protected) | ||
d.setPrivateWithin(NoSymbol) | ||
d | ||
|
||
|
||
end BinaryAPIAnnotations | ||
|
||
object BinaryAPIAnnotations: | ||
val name: String = "binaryAPIAnnotations" | ||
val description: String = "makes @binaryAPI definitions public" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package scala.annotation | ||
|
||
/** TODO */ | ||
@experimental | ||
class binaryAPI extends scala.annotation.StaticAnnotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- Error: tests/neg/binaryAPI.scala:6:18 ------------------------------------------------------------------------------- | ||
6 |@binaryAPI object B // error // TODO support? | ||
| ^ | ||
| @binaryAPI cannot be used on object definitions | ||
-- Error: tests/neg/binaryAPI.scala:7:17 ------------------------------------------------------------------------------- | ||
7 |@binaryAPI class C: // error | ||
| ^ | ||
| @binaryAPI cannot be used on class definitions | ||
-- Error: tests/neg/binaryAPI.scala:8:25 ------------------------------------------------------------------------------- | ||
8 | @binaryAPI private def f: Unit = // error | ||
| ^ | ||
| @binaryAPI cannot be used on private definitions. | ||
| | ||
| Could use private[C] or protected instead. | ||
-- Error: tests/neg/binaryAPI.scala:9:19 ------------------------------------------------------------------------------- | ||
9 | @binaryAPI def g = () // error | ||
| ^ | ||
| @binaryAPI cannot be used on local definitions. | ||
-- Error: tests/neg/binaryAPI.scala:11:19 ------------------------------------------------------------------------------ | ||
11 |class D(@binaryAPI x: Int) // error | ||
| ^ | ||
| @binaryAPI cannot be used on private definitions. | ||
| | ||
| Could use private[D] or protected instead. | ||
-- Error: tests/neg/binaryAPI.scala:12:19 ------------------------------------------------------------------------------ | ||
12 |class E[@binaryAPI T] // error | ||
| ^ | ||
| @binaryAPI cannot be used on type definitions | ||
-- Error: tests/neg/binaryAPI.scala:14:16 ------------------------------------------------------------------------------ | ||
14 |@binaryAPI enum Enum1: // error | ||
| ^ | ||
| @binaryAPI cannot be used on enum definitions. | ||
-- Error: tests/neg/binaryAPI.scala:18:18 ------------------------------------------------------------------------------ | ||
18 | @binaryAPI case A // error | ||
| ^ | ||
| @binaryAPI cannot be used on enum definitions. | ||
-- Error: tests/neg/binaryAPI.scala:19:18 ------------------------------------------------------------------------------ | ||
19 | @binaryAPI case B(a: Int) // error | ||
| ^ | ||
| @binaryAPI cannot be used on enum definitions. | ||
-- Error: tests/neg/binaryAPI.scala:5:16 ------------------------------------------------------------------------------- | ||
5 |@binaryAPI type A // error | ||
| ^ | ||
| @binaryAPI cannot be used on type definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package foo | ||
|
||
import scala.annotation.binaryAPI | ||
|
||
@binaryAPI type A // error | ||
@binaryAPI object B // error // TODO support? | ||
@binaryAPI class C: // error | ||
@binaryAPI private def f: Unit = // error | ||
@binaryAPI def g = () // error | ||
() | ||
class D(@binaryAPI x: Int) // error | ||
class E[@binaryAPI T] // error | ||
|
||
@binaryAPI enum Enum1: // error | ||
case A | ||
|
||
enum Enum2: | ||
@binaryAPI case A // error | ||
@binaryAPI case B(a: Int) // error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.quoted.* | ||
import scala.annotation.binaryAPI | ||
|
||
class Macro: | ||
inline def foo = ${ Macro.fooImpl } | ||
|
||
object Macro: | ||
@binaryAPI private[Macro] def fooImpl(using Quotes) = '{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test = | ||
new Macro().foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package bar | ||
|
||
import scala.quoted.* | ||
import scala.annotation.binaryAPI | ||
|
||
inline def foo = ${ fooImpl } | ||
|
||
@binaryAPI private[bar] def fooImpl(using Quotes) = '{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def test = bar.foo |
Oops, something went wrong.