Skip to content

Commit ed5304e

Browse files
committed
Address review comments
Change scheme how sourcenames are computed from filenames to account for filenames that have additional `.`s in them. Fix comments.
1 parent d874964 commit ed5304e

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

+6-3
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,8 @@ object desugar {
10221022
else Apply(ref(tupleTypeRef.classSymbol.companionModule.termRef), ts)
10231023
}
10241024

1025-
/** Group all definitions that can't be at the toplebel in
1026-
* an object named `<source>#object` where `<source>` is the name of the source file.
1025+
/** Group all definitions that can't be at the toplevel in
1026+
* an object named `<source>$package` where `<source>` is the name of the source file.
10271027
* Definitions that can't be at the toplevel are:
10281028
*
10291029
* - all pattern, value and method definitions
@@ -1045,7 +1045,10 @@ object desugar {
10451045
val (nestedStats, topStats) = pdef.stats.partition(needsObject)
10461046
if (nestedStats.isEmpty) pdef
10471047
else {
1048-
val sourceName = ctx.source.file.name.takeWhile(_ != '.')
1048+
var fileName = ctx.source.file.name
1049+
val end = fileName.lastIndexOf('.') // drop extension
1050+
val start = fileName.lastIndexOf('.', end - 1) // drop any prefix before another `.`
1051+
val sourceName = fileName.substring(start + 1, end)
10491052
val groupName = (sourceName ++ str.TOPLEVEL_SUFFIX).toTermName
10501053
val grouped = ModuleDef(groupName, Template(emptyConstructor, Nil, Nil, EmptyValDef, nestedStats))
10511054
cpy.PackageDef(pdef)(pdef.pid, topStats :+ grouped)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1974,8 +1974,8 @@ object SymDenotations {
19741974
* is as follows:
19751975
*
19761976
* If this is the scala package look in the package first, and if nothing is found
1977-
* there, look in the package object second. Otherwise, look in the package object
1978-
* first, and if nothing is found there, in the package second.
1977+
* there, look in the package object second. Otherwise, look in the both the package object
1978+
* and the package and form a union of the results.
19791979
*
19801980
* The reason for the special treatment of the scala package is that if we
19811981
* complete it too early, we freeze its superclass Any, so that no members can

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class Typer extends Namer
269269
!curOwner.isPackageObject
270270
// Package objects are never searched directly. We wait until we
271271
// hit the enclosing package. That way we make sure we consider
272-
// all overloaded altrenatives of a definition, even if they are
272+
// all overloaded alternatives of a definition, even if they are
273273
// in different source files.
274274

275275
if (isNewDefScope) {

0 commit comments

Comments
 (0)