Skip to content
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

Update scala-library to 2.13.9 #370

Merged
merged 4 commits into from
Sep 27, 2022
Merged

Update scala-library to 2.13.9 #370

merged 4 commits into from
Sep 27, 2022

Conversation

typelevel-steward[bot]
Copy link
Contributor

Updates org.scala-lang:scala-library from 2.13.8 to 2.13.9.
GitHub Release Notes - Version Diff

I'll automatically update this PR to resolve conflicts as long as you don't change it yourself.

If you'd like to skip this version, you can just close this PR. If you have any feedback, just mention me in the comments below.

Configure Scala Steward for your repository with a .scala-steward.conf file.

Have a fantastic day writing Scala!

Adjust future updates

Add this to your .scala-steward.conf file to ignore future updates of this dependency:

updates.ignore = [ { groupId = "org.scala-lang", artifactId = "scala-library" } ]

Or, add this to slow down future updates of this dependency:

dependencyOverrides = [{
  pullRequests = { frequency = "@monthly" },
  dependency = { groupId = "org.scala-lang", artifactId = "scala-library" }
}]

labels: library-update, early-semver-patch, semver-spec-patch, commit-count:n:2

@@ -32,6 +30,10 @@ trait MouseFunctions {
* @param a
* - the value to be evaluated and ignored.
*/
def ignore(@nowarn a: Any): Unit = ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the new behavior in Scala 2.13.9, this @nowarn was marked as unused.

home/runner/work/mouse/mouse/shared/src/main/scala/mouse/MouseFunctions.scala:35:15: @nowarn annotation does not suppress any warnings
[error] def ignore(@nowarn a: Any): Unit = ()

And it's done intentionally. So we had to handle this issue with some workaround.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benhutchison your thoughts on this would be appreciated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoying and ironic that suppressing warnings generates a warning!

But if there's no warning, can we remove the annotation?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new behavior is only for 2.13.9. So, if we just remove the annotation, then for 2.12 and 3 that will cause warnings about unused function argument.

@benhutchison
Copy link
Member

benhutchison commented Sep 25, 2022 via email

@danicheg
Copy link
Member

Alternative would be a version specific source file but that's a lot of
bother for such a small issue..

I agree with this. This approach would require us to do a lot of copy-pasting. Our codebase will lose some maintainability.

Maybe we hold off on 2.13.9 and see if
they reverse it due to popular outcry?

It took 9 months for the new release to come. It will be a long run. 🤷🏻‍♂️

@benhutchison
Copy link
Member

benhutchison commented Sep 25, 2022 via email

@satorg
Copy link

satorg commented Sep 25, 2022

I agree with this. This approach would require us to do a lot of copy-pasting. Our codebase will lose some maintainability.

Alternatively, it is possible to implement a version-specific @nowarn. But if you think Scala-compiler folks may decide to revert the change, then it is not worth it, apparently.

@satorg
Copy link

satorg commented Sep 25, 2022

... or perhaps another alternative could be leveraging -Wconf for 2.13.9 with the origin (UPD. or site?) parameter to suppress unnecessary "unused" warnings:

Syntax: -Wconf:<filters>:<action>,<filters>:<action>,...
multiple <filters> are combined with &, i.e., <filter>&...&<filter>

...

<filter>
  ...
  - Site where the warning is triggered: site=my\.package\..*
    The regex must match the full name (`package.Class.method`) of the warning position.

  - Origin of deprecation: origin=external\.package\..*
    The regex must match the full name (`package.Class.method`) of the deprecated entity.

But it would require to point out all the undesired warning origins in compiler options, of course 🤷

@danicheg
Copy link
Member

@satorg

or perhaps another alternative could be leveraging -Wconf for 2.13.9 with the origin (UPD. or site?) parameter to suppress unnecessary "unused" warnings:

Wouldn't that lead to warnings on the user side on using the ignore function?

@satorg
Copy link

satorg commented Sep 27, 2022

@danicheg I have been poking around the -Wconf and other compiler settings. And there are good and bad news to bring up:

  • Bad news: I could not make -Wconf working with the site filter option.
    The only filters that are working for mouse.MouseFunctions#ignore are something like site=.* or site=^.*$ or site=^.?$ or something like that. Which basically means that "site" is just empty (!) there. Perhaps @som-snytt could help to clarify on how the site filter is supposed to work in such cases.
  • Good news: turned out that although Scala v2.13.9 does not tolerate @nowarn anymore but it does tolerate @unused.
  • Bad news: (well, not the news, actually) Scala v2.12 does not have @unused.
  • Good news: the latter can be simulated via @nowarn in a "compiler-compat" way.
  • Bad news: by default it produces another warning.
  • Good news: that warning can be suppressed gracefully too.

Bottomline: it seems that it can be made working afterall. See #372 as an example on how it could be addressed.

@satorg
Copy link

satorg commented Sep 27, 2022

...I would also dare to argue that regardless of the changes in v2.13.9 the @unused annotation is generally preferable over @nowarn for suppressing various unused stuff.

@som-snytt
Copy link

som-snytt commented Sep 27, 2022

Under -Wunused:params -Xlint or equivalent:

// 2.12.17, 2.13.8 warn C&D
// 2.13.9 warns D only
// the E is silent

import annotation._

class C {
  def f(x: String): Unit = ()
}

class D {
  def f(x: String): Unit = (): Unit
}

class E {
  def f(@nowarn x: String): Unit = (): Unit
}

Don't miss the proposal for -Xlint:confused scala/bug#11631 (comment)

This proposal from the original ticket was not adopted:

Not warning on meh is an easy win.

@som-snytt
Copy link

I'm reminded that this does not warn because the signature is foreordained:

trait T {
  def f(x: String): Unit
}

class X extends T {
  def f(x: String): Unit = (): Unit
}

@som-snytt
Copy link

Also from the original proposal for @unused, this does not warn:

def dep(@deprecated("not used", since="now") x: String): Unit = (): Unit

So the idea was for unused to extend deprecated. The proposal for custom unused extending nowarn rang this bell.

@satorg
Copy link

satorg commented Sep 27, 2022

Yeah, I saw that @deprecated-based approach is used in the scala-collection-compat library:
https://github.com/scala/scala-collection-compat/blob/d6723b241ab943f8f0e7da21292c7994ce4d9f80/compat/src/main/scala-2.11_2.12/scala/annotation/unused.scala#L15

Unfortunately it is not perfect either. Consider this simplified example from cats (syntax for Either, actually):

import scala.reflect.ClassTag

trait NotNull[A]

class CatchOnlyPartiallyApplied[T](val dummy: Boolean) extends AnyVal {
  //def apply[A](f: => A)(implicit CT: ClassTag[T], @deprecated("unused", "now") NT: NotNull[T]): Either[T, A] =
  //def apply[A](f: => A)(implicit CT: ClassTag[T], @annotation.nowarn("cat=unused") NT: NotNull[T]): Either[T, A] =
  def apply[A](f: => A)(implicit CT: ClassTag[T], NT: NotNull[T]): Either[T, A] =
    try {
      Right(f)
    } catch {
      case t if CT.runtimeClass.isInstance(t) =>
        Left(t.asInstanceOf[T])
    }
}

The line without any annotation produces an "unused" warning (apparently)
v2.12.17:

[warn] ./fromCatsEitherSyntax.scala:8:51: parameter value NT in method apply is never used
[warn]   def apply[A](f: => A)(implicit CT: ClassTag[T], NT: NotNull[T]): Either[T, A] =
[warn]                                                   ^

v2.13.9:

[warn] ./fromCatsEitherSyntax.scala:8:51: parameter value NT in method apply is never used
[warn]   def apply[A](f: => A)(implicit CT: ClassTag[T], NT: NotNull[T]): Either[T, A] =
[warn]                                                   ^^^^^^^^^^^^^^

However(!), if we try to utilize @deprecated to suppress the unused warning, then we'll end up with a way weirder one:
v2.12.17:

[warn] ./fromCatsEitherSyntax.scala:9:5: value NT is deprecated (since now): unused
[warn]     try {
[warn]     ^

v2.13.9:

[warn] ./fromCatsEitherSyntax.scala:9:5: value NT is deprecated (since now): unused
[warn]     try {
[warn]     ^

Whereas @nowarn("cat=unused") (or a custom @unused inherited from that) works just fine for this case 🤷

@danicheg
Copy link
Member

It blows my mind, but type ascription really helps to tackle the issue with @nowarn. @som-snytt thanks for this workaround.
@benhutchison could you re-review this PR? Now it seems pretty fine to get PR merged.

Copy link
Member

@benhutchison benhutchison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple!

@danicheg danicheg merged commit 3f8bb6a into main Sep 27, 2022
@danicheg danicheg deleted the update/scala-library-2.13.9 branch September 27, 2022 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants