Skip to content

Commit 2ee0c7e

Browse files
oderskynatsukagami
authored andcommitted
Mitigate change in status of scala.caps
`scala.caps`` was an object until 3.6, it is a package from 3.7. Without special handling this would cause a TypeError to be thrown if a build has several versions of the Scala standard library on the classpath. This was the case for 29 projects in the open CB. These projects should be updated. But until that's the case we issue a warning instead of a hard failure.
1 parent b989a7b commit 2ee0c7e

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ object SymbolLoaders {
7878
* and give them `completer` as type.
7979
*/
8080
def enterPackage(owner: Symbol, pname: TermName, completer: (TermSymbol, ClassSymbol) => PackageLoader)(using Context): Symbol = {
81-
val preExisting = owner.info.decls lookup pname
81+
val preExisting = owner.info.decls.lookup(pname)
8282
if (preExisting != NoSymbol)
8383
// Some jars (often, obfuscated ones) include a package and
8484
// object with the same name. Rather than render them unusable,
@@ -95,6 +95,18 @@ object SymbolLoaders {
9595
s"Resolving package/object name conflict in favor of object ${preExisting.fullName}. The package will be inaccessible.")
9696
return NoSymbol
9797
}
98+
else if pname == nme.caps && owner == defn.ScalaPackageClass then
99+
// `scala.caps`` was an object until 3.6, it is a package from 3.7. Without special handling
100+
// this would cause a TypeError to be thrown below if a build has several versions of the
101+
// Scala standard library on the classpath. This was the case for 29 projects in OpenCB.
102+
// These projects should be updated. But until that's the case we issue a warning instead
103+
// of a hard failure.
104+
report.warning(
105+
em"""$owner contains object and package with same name: $pname.
106+
|This indicates that there are several versions of the Scala standard library on the classpath.
107+
|The build should be reconfigured so that only one version of the standard library is on the classpath.""")
108+
owner.info.decls.openForMutations.unlink(preExisting)
109+
owner.info.decls.openForMutations.unlink(preExisting.moduleClass)
98110
else
99111
throw TypeError(
100112
em"""$owner contains object and package with same name: $pname

tests/neg/i22890.check

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- [E161] Naming Error: tests/neg/i22890/caps_1.java:3:0 ---------------------------------------------------------------
2+
3 |class caps { // error: caps is already defined as package caps
3+
|^
4+
|caps is already defined as package scala.caps
5+
package scala contains object and package with same name: caps.
6+
This indicates that there are several versions of the Scala standard library on the classpath.
7+
The build should be reconfigured so that only one version of the standard library is on the classpath.

tests/neg/i22890/Test_2.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@main def Test =
2+
println("hello")
3+
// nopos-warn

tests/neg/i22890/caps_1.java

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package scala;
2+
3+
class caps { // error: caps is already defined as package caps
4+
static public void foo() {}
5+
}

0 commit comments

Comments
 (0)