Skip to content

Commit eb7e18d

Browse files
committed
Fix param accessors
1 parent 665fc74 commit eb7e18d

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,8 @@ object Checking {
542542
if sym.is(Enum) then fail(em"@publicInBinary cannot be used on enum definitions")
543543
else if sym.isType && !sym.is(Module) && !(sym.is(Given) || sym.companionModule.is(Given)) then fail(em"@publicInBinary cannot be used on ${sym.showKind} definitions")
544544
else if !sym.owner.isClass && !(sym.is(Param) && sym.owner.isConstructor) then fail(em"@publicInBinary cannot be used on local definitions")
545-
else if sym.is(Private) && !sym.privateWithin.exists && !sym.isConstructor then fail(em"@publicInBinary cannot be used on private definitions\n\nThe definition could be `private[${sym.owner.name}]` or `protected` instead")
545+
else if sym.is(ParamAccessor) && sym.is(Private) then fail(em"@publicInBinary cannot be non `val` constructor parameters")
546+
else if sym.is(Private) && !sym.privateWithin.exists && !sym.isConstructor then fail(em"@publicInBinary cannot be used on private definitions\n\nConsider using `private[${sym.owner.name}]` or `protected` instead")
546547
if (sym.hasAnnotation(defn.NativeAnnot)) {
547548
if (!sym.is(Deferred))
548549
fail(NativeMembersMayNotHaveImplementation(sym))

tests/neg/publicInBinary.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
21 | @publicInBinary case B(a: Int) // error
2323
| ^
2424
| @publicInBinary cannot be used on enum definitions
25+
-- Error: tests/neg/publicInBinary.scala:25:18 -------------------------------------------------------------------------
26+
25 | @publicInBinary x: Int, // error
27+
| ^
28+
| @publicInBinary cannot be non `val` constructor parameters
29+
-- Error: tests/neg/publicInBinary.scala:26:31 -------------------------------------------------------------------------
30+
26 | @publicInBinary private[Bar] y: Int, // error
31+
| ^
32+
| @publicInBinary cannot be non `val` constructor parameters
2533
-- Error: tests/neg/publicInBinary.scala:7:21 --------------------------------------------------------------------------
2634
7 |@publicInBinary type A // error
2735
| ^

tests/neg/publicInBinary.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,10 @@ def f(@publicInBinary x: Int) = 3 // error
1919
enum Enum2:
2020
@publicInBinary case A // error
2121
@publicInBinary case B(a: Int) // error
22+
23+
24+
class Bar (
25+
@publicInBinary x: Int, // error
26+
@publicInBinary private[Bar] y: Int, // error
27+
@publicInBinary private[Bar] val z: Int,
28+
)

tests/run/publicInBinary/Lib_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ package constructors {
121121
class Foo @publicInBinary private[constructors] (x: Int):
122122
@publicInBinary private[constructors] def this(x: Int, y: Int) = this(x + y)
123123

124-
class Bar @publicInBinary(@publicInBinary private[Bar] x: Int):
124+
class Bar @publicInBinary(@publicInBinary private[Bar] val x: Int):
125125
@publicInBinary private def this(x: Int, y: Int) = this(x + y)
126126
inline def bar: Bar = new Bar(x, x)
127127

0 commit comments

Comments
 (0)