Skip to content

Commit

Permalink
un-deprecate package object inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
lrytz committed Jan 18, 2024
1 parent d7ed19d commit b353f1d
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 56 deletions.
5 changes: 0 additions & 5 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3392,11 +3392,6 @@ self =>
val templateOffset = if (body.isEmpty && in.lastOffset < tstart) in.lastOffset else tstart
val templatePos = o2p(templateOffset)

// warn now if user wrote parents for package object; `gen.mkParents` adds AnyRef to parents
if (currentRun.isScala3 && name == nme.PACKAGEkw && !parents.isEmpty)
migrationWarning(tstart, sm"""|package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
|drop the `extends` clause or use a regular object instead""", "3.0.0")

atPos(templateOffset) {
// Exclude only the 9 primitives plus AnyVal.
if (inScalaRootPackage && ScalaValueClassNames.contains(name))
Expand Down
13 changes: 0 additions & 13 deletions test/files/neg/deprecate_package_object_extends.check

This file was deleted.

5 changes: 0 additions & 5 deletions test/files/neg/deprecate_package_object_extends.scala

This file was deleted.

8 changes: 1 addition & 7 deletions test/files/neg/t11921b.check
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
t11921b.scala:135: error: could not find implicit value for parameter i: Int
def u = t // doesn't compile in Scala 2 (maybe there's a ticket for that)
^
t11921b.scala:151: error: package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
drop the `extends` clause or use a regular object instead
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration
package object pt12850 extends t12850 {
^
t11921b.scala:11: error: reference to x is ambiguous;
it is both defined in the enclosing object Test and inherited in the enclosing class D as value x (defined in class C)
In Scala 2, symbols inherited from a superclass shadow symbols defined in an outer scope.
Expand Down Expand Up @@ -79,4 +73,4 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=test10.C.v
def v = t(lo) // error
^
10 errors
9 errors
6 changes: 1 addition & 5 deletions test/files/neg/t12798-migration.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ To express the assignment expression, wrap it in brackets, e.g., `{ z = ... }`.
t12798-migration.scala:25: warning: unary prefix operator definition with empty parameter list is unsupported: instead, remove () to declare as `def unary_- = -42` [quickfixable]
def unary_-() = -42
^
t12798-migration.scala:28: warning: package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
drop the `extends` clause or use a regular object instead
package object tester extends Runnable {
^
t12798-migration.scala:33: warning: procedure syntax is deprecated for constructors: add `=`, as in method definition [quickfixable]
def this(s: String) { this() }
^
Expand Down Expand Up @@ -50,5 +46,5 @@ case class `case mods propagate` private (s: String)
t12798-migration.scala:52: warning: access modifiers for `apply` method are copied from the case class constructor
case class `copyless case mods propagate` private (s: String) {
^
15 warnings
14 warnings
1 error
8 changes: 1 addition & 7 deletions test/files/neg/t12798.check
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration
def unary_-() = -42
^
t12798.scala:28: error: package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
drop the `extends` clause or use a regular object instead
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration
package object tester extends Runnable {
^
t12798.scala:33: error: procedure syntax is deprecated for constructors: add `=`, as in method definition [quickfixable]
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration
Expand Down Expand Up @@ -75,4 +69,4 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=copyless case mods propagate.apply
case class `copyless case mods propagate` private (s: String) {
^
15 errors
14 errors
8 changes: 1 addition & 7 deletions test/files/neg/t12816.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
t12816.scala:8: error: package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
drop the `extends` clause or use a regular object instead
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration
package object p extends U {
^
t12816.scala:29: error: reference to c is ambiguous;
it is both defined in the enclosing package p and inherited in the enclosing trait RR as method c (defined in trait T)
In Scala 2, symbols inherited from a superclass shadow symbols defined in an outer scope.
Expand All @@ -22,4 +16,4 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=p.RR.n3
def n3: Z // warn
^
3 errors
2 errors
8 changes: 1 addition & 7 deletions test/files/neg/t12816b.check
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
A.scala:5: error: package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
drop the `extends` clause or use a regular object instead
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration
package object p extends U {
^
B.scala:19: error: reference to c is ambiguous;
it is both defined in the enclosing package p and inherited in the enclosing trait RR as method c (defined in trait T)
In Scala 2, symbols inherited from a superclass shadow symbols defined in an outer scope.
Expand All @@ -22,4 +16,4 @@ Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=p.RR.n3
def n3: Z // warn
^
3 errors
2 errors

0 comments on commit b353f1d

Please sign in to comment.