Skip to content

Backport "Mitigate change in status of scala.caps" to 3.7.0 #22966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object SymbolLoaders {
* and give them `completer` as type.
*/
def enterPackage(owner: Symbol, pname: TermName, completer: (TermSymbol, ClassSymbol) => PackageLoader)(using Context): Symbol = {
val preExisting = owner.info.decls lookup pname
val preExisting = owner.info.decls.lookup(pname)
if (preExisting != NoSymbol)
// Some jars (often, obfuscated ones) include a package and
// object with the same name. Rather than render them unusable,
Expand All @@ -95,6 +95,18 @@ object SymbolLoaders {
s"Resolving package/object name conflict in favor of object ${preExisting.fullName}. The package will be inaccessible.")
return NoSymbol
}
else if pname == nme.caps && owner == defn.ScalaPackageClass then
// `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 below if a build has several versions of the
// Scala standard library on the classpath. This was the case for 29 projects in OpenCB.
// These projects should be updated. But until that's the case we issue a warning instead
// of a hard failure.
report.warning(
em"""$owner contains object and package with same name: $pname.
|This indicates that there are several versions of the Scala standard library on the classpath.
|The build should be reconfigured so that only one version of the standard library is on the classpath.""")
owner.info.decls.openForMutations.unlink(preExisting)
owner.info.decls.openForMutations.unlink(preExisting.moduleClass)
else
throw TypeError(
em"""$owner contains object and package with same name: $pname
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i22890.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- [E161] Naming Error: tests/neg/i22890/caps_1.java:3:0 ---------------------------------------------------------------
3 |class caps { // error: caps is already defined as package caps
|^
|caps is already defined as package scala.caps
package scala contains object and package with same name: caps.
This indicates that there are several versions of the Scala standard library on the classpath.
The build should be reconfigured so that only one version of the standard library is on the classpath.
3 changes: 3 additions & 0 deletions tests/neg/i22890/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@main def Test =
println("hello")
// nopos-warn
5 changes: 5 additions & 0 deletions tests/neg/i22890/caps_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package scala;

class caps { // error: caps is already defined as package caps
static public void foo() {}
}
Loading