Skip to content

Commit 34d4e80

Browse files
committed
Add spec and test for private toplevel definitions
1 parent 8ced7cc commit 34d4e80

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

docs/docs/reference/dropped-features/package-objects.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: doc-page
3-
title: "Instance Definitions"
3+
title: "Dropped: Package Objects"
44
---
55

66
Package objects
@@ -40,3 +40,8 @@ If a source file `src.scala` contains such toplevel definitions, they will be pu
4040
**Note 2:** A toplevel main method `def main(args: Array[String]): Unit = ...` is wrapped as any other method. If it appears
4141
in a source file `src.scala`, it could be invoked from the command line using a command like `scala src$package`. Since the
4242
"program name" is mangled it is recommended to always put `main` methods in explicitly named objects.
43+
44+
### Private toplevel definitions
45+
46+
If a private toplevel definition is wrapped in a synthetic object, it is visible only
47+
in definitions in the same source file. By contrast, a package-private definition is visible

tests/neg/toplevel-privates/A.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package p
2+
3+
private val x = 10
4+
5+
val y = x
6+
7+
private[p] val xx = 10
8+
9+
val yy = xx
10+
11+
private class C
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package p
2+
3+
val x1 = x // error
4+
5+
val y1 = y // ok
6+
7+
val xx1 = xx // ok
8+
9+
val yy1 = yy // ok
10+
11+
val c = new C // ok

0 commit comments

Comments
 (0)