Skip to content

Commit c0e3456

Browse files
committed
Change scheme to name package object wrappers
It's now src$package instead of src#object
1 parent fbd4859 commit c0e3456

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

compiler/src/dotty/tools/dotc/core/StdNames.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object StdNames {
2020
final val INITIALIZER_PREFIX = "initial$"
2121
final val AVOID_CLASH_SUFFIX = "$_avoid_name_clash_$"
2222
final val MODULE_SUFFIX = "$"
23-
final val TOPLEVEL_SUFFIX = "#object"
23+
final val TOPLEVEL_SUFFIX = "$package"
2424
final val NAME_JOIN = "$"
2525
final val DEFAULT_GETTER = "$default$"
2626
final val LOCALDUMMY_PREFIX = "<local " // owner of local blocks

compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import dotty.tools.io.{ ClassPath, ClassRepresentation, AbstractFile }
88
import config.Config
99
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, Names._
1010
import NameOps._
11+
import StdNames.str
1112
import Decorators.{PreNamedString, StringInterpolators}
1213
import classfile.ClassfileParser
1314
import util.Stats
@@ -236,11 +237,18 @@ object SymbolLoaders {
236237

237238
private[core] val currentDecls: MutableScope = new PackageScope()
238239

239-
def isFlatName(name: SimpleName): Boolean = name.lastIndexOf('$', name.length - 2) >= 0
240+
private def isFlatName(name: SimpleName): Boolean = {
241+
val idx = name.lastIndexOf('$', name.length - 2)
242+
idx >= 0 &&
243+
(idx + str.TOPLEVEL_SUFFIX.length + 1 != name.length || !name.endsWith(str.TOPLEVEL_SUFFIX))
244+
}
240245

241-
def isFlatName(classRep: ClassRepresentation): Boolean = {
242-
val idx = classRep.name.indexOf('$')
243-
idx >= 0 && idx < classRep.name.length - 1
246+
/** Name of class contains `$`, excepted names ending in `$package` */
247+
def hasFlatName(classRep: ClassRepresentation): Boolean = {
248+
val name = classRep.name
249+
val idx = name.lastIndexOf('$', name.length - 2)
250+
idx >= 0 &&
251+
(idx + str.TOPLEVEL_SUFFIX.length + 1 != name.length || !name.endsWith(str.TOPLEVEL_SUFFIX))
244252
}
245253

246254
def maybeModuleClass(classRep: ClassRepresentation): Boolean = classRep.name.last == '$'
@@ -253,11 +261,11 @@ object SymbolLoaders {
253261
val classReps = classPath.list(packageName).classesAndSources
254262

255263
for (classRep <- classReps)
256-
if (!maybeModuleClass(classRep) && isFlatName(classRep) == flat &&
264+
if (!maybeModuleClass(classRep) && hasFlatName(classRep) == flat &&
257265
(!flat || isAbsent(classRep))) // on 2nd enter of flat names, check that the name has not been entered before
258266
initializeFromClassPath(root.symbol, classRep)
259267
for (classRep <- classReps)
260-
if (maybeModuleClass(classRep) && isFlatName(classRep) == flat &&
268+
if (maybeModuleClass(classRep) && hasFlatName(classRep) == flat &&
261269
isAbsent(classRep))
262270
initializeFromClassPath(root.symbol, classRep)
263271
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ Package objects are no longer needed since all kinds of definitions and statemen
2020
```
2121
There may be several source files in a package containing such toplevel definitions, and source files can freely mix toplevel value, method, and tyoe definitions with classes and objects.
2222

23-
The compiler generates synthetic objects that wrap toplevel statements that are not imports, or class or object definitions. If a source file `src.scala` contains such toplevel statements, they will be put in a synthetic object named `src#object`. The wrapping is transparent, however. The definitions in `f` can still be accessed
24-
as members of the enclosing package.
23+
The compiler generates synthetic objects that wrap toplevel statements that are not imports, or class or object definitions. If a source file `src.scala` contains such toplevel statements, they will be put in a synthetic object named `src$package`. The wrapping is transparent, however. The definitions in `f` can still be accessed as members of the enclosing package.

0 commit comments

Comments
 (0)