How to ignore a "side-effecting nullary methods are discouraged" warning?

150 views
Skip to first unread message

David Miguel Antunes

unread,
Jan 8, 2015, 6:51:00 AM1/8/15
to scala...@googlegroups.com
Hi,

I want to compile with "-Xfatal-warnings", but I have a situation where I cannot avoid a "side-effecting nullary methods are discouraged" warning:
trait LibraryCode {
// This is in a library, I can't change it!:
def someMethod: Unit = {}
}

trait MyCode extends LibraryCode {

var mutable = 0
override def someMethod: Unit = mutable = 1
// Compiler says:
// side-effecting nullary methods are discouraged: suggest defining as `def someMethod()` instead
}
(I'm overriding a method which is on a library, so I can't change the method signature to fix the "side-effecting nullary methods are discouraged" warning.)

Is there a way I can ask the compiler to ignore this warning?

Thanks!
David

Miles Sabin

unread,
Jan 8, 2015, 7:16:29 AM1/8/15
to David Miguel Antunes, scala...@googlegroups.com
You can change the signature, but unfortunately that just gets you a
different warning,

trait MyCode extends LibraryCode {

var mutable = 0
override def someMethod(): Unit = mutable = 1
}

<console>:11: warning: non-nullary method overrides nullary method
override def someMethod(): Unit = mutable = 1
^
defined trait MyCode

Cheers,


Miles
> --
> You received this message because you are subscribed to the Google Groups
> "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scala-user+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
g+: http://www.milessabin.com
http://twitter.com/milessabin

David Miguel Antunes

unread,
Jan 8, 2015, 7:19:14 AM1/8/15
to Miles Sabin, scala...@googlegroups.com
Hi Miles,

Yep, I tried that and got the warning  : )
Is there any warning suppression flag for this case, or something like that?

Thanks,
David

Miles Sabin

unread,
Jan 8, 2015, 7:21:06 AM1/8/15
to David Miguel Antunes, scala...@googlegroups.com
On Thu, Jan 8, 2015 at 12:18 PM, David Miguel Antunes
<davidbr...@gmail.com> wrote:
> Yep, I tried that and got the warning : )
> Is there any warning suppression flag for this case, or something like that?

Unfortunately not.

Cheers,


Miles

Jon Pretty

unread,
Jan 8, 2015, 7:25:04 AM1/8/15
to Miles Sabin, type...@googlegroups.com, David Miguel Antunes, scala...@googlegroups.com
+typelevel

I seem to remember we discussed a "suppress warning" annotation for Typelevel Scala at some point that would work around situations like this. I think I wanted to call it @sic, though Lars thought that was too easy and would lead to overliberal usage, so preferred @entschuldigenSieBitte.

We should revive that idea, possibly compromising on @suppressWarning.

Jon

On 8 January 2015 at 12:15, Miles Sabin <mi...@milessabin.com> wrote:



--
Jon Pretty | @propensive

Som Snytt

unread,
Jan 8, 2015, 11:02:31 AM1/8/15
to Jon Pretty, Miles Sabin, type...@googlegroups.com, David Miguel Antunes, scala...@googlegroups.com
Depending on what you mean by ignore:

$ scalac -Xlint:help
Enable or disable specific warnings
  adapted-args               Warn if an argument list is modified to match the receiver.
  nullary-unit               Warn when nullary methods return Unit.
  inaccessible               Warn about inaccessible types in method signatures.
  nullary-override           Warn when non-nullary `def f()' overrides nullary `def f'.
  infer-any                  Warn when a type argument is inferred to be `Any`.
  missing-interpolator       A string literal appears to be missing an interpolator id.
  doc-detached               A ScalaDoc comment appears to be detached from its element.
  private-shadow             A private field (or class parameter) shadows a superclass field.
  type-parameter-shadow      A local type parameter shadows a type already in scope.
  poly-implicit-overload     Parameterized overloaded implicit methods are not visible as view bounds.
  option-implicit            Option.apply used implicit view.
  delayedinit-select         Selecting member of DelayedInit
  by-name-right-associative  By-name parameter of right associative operator.
  package-object-classes     Class or object defined in package object.
  unsound-match              Pattern match may not be typesafe.
$ scala
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_11).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :se -Xlint:-nullary-unit,_

scala> trait X { def x = () }
defined trait X

scala> { val hi = 42 ; "$hi, world" }
<console>:8: warning: possible missing interpolator: detected interpolated identifier `$hi`
              { val hi = 42 ; "$hi, world" }
                              ^
res0: String = $hi, world



--
You received this message because you are subscribed to the Google Groups "Typelevel Users & Development List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to typelevel+...@googlegroups.com.
To post to this group, send email to type...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/typelevel/CAE45xch7j4_ZonJrnsQPoiS8442%3DLx4UJhEiR63BwFy_Q5k4gQ%40mail.gmail.com.

David Miguel Antunes

unread,
Jan 12, 2015, 5:44:12 AM1/12/15
to Som Snytt, Jon Pretty, Miles Sabin, type...@googlegroups.com, scala...@googlegroups.com
Hi Som,

Sorry for the time to answer. Yep, it was exactly that I was looking for! - thank you : )

Thanks,
David

virtualeyes

unread,
Apr 27, 2015, 1:23:38 PM4/27/15
to type...@googlegroups.com, prope...@gmail.com, davidbr...@gmail.com, scala...@googlegroups.com, mi...@milessabin.com
-Xlint:-nullary-unit,_

Exactly what I needed with -Yno-adapted-args and -Xfatal-warnings

Thanks ;-)
Reply all
Reply to author
Forward
0 new messages