-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
area:lintingLinting warnings enabled with -W or -XlintLinting warnings enabled with -W or -Xlintitype:bug
Description
Compiler version
3.7.4
Minimized code
//> using scala 3.7.4
//> using options -Wunused:all -Wnonunit-statement -Vprint:ty,inlining,ref -deprecation
import annotation.*
object X:
@deprecated("use f instead for noise suppression")
def b(s: String): Boolean = s.length > 3
inline transparent def f(inline cond: Boolean = false) =
inline if cond then b("hello"): @nowarn else b("goodbye"): Unit @nowarn
//inline if cond then b("hello") else b("goodbye"): Unit
@main def test = println:
//b("hello")
X.f()
X.f(cond = true)
//"hello, world"Output
-- Warning: /home/amarki/snips/union-usage.scala:11:24 -------------------------
11 | inline if cond then b("hello"): @nowarn else b("goodbye"): Unit @nowarn
| ^^^^^^^^^^^^^^^^^^^
|@nowarn annotation does not suppress any warnings but matches a diagnostic
-- Warning: /home/amarki/snips/union-usage.scala:11:68 -------------------------
11 | inline if cond then b("hello"): @nowarn else b("goodbye"): Unit @nowarn
| ^^^^^^^
| @nowarn annotation does not suppress any warningswithout nowarn
-- [E176] Potential Issue Warning: /home/amarki/snips/union-usage.scala:16:5 ---
16 | X.f()
| ^^^^^
| unused value of type Boolean
|----------------------------------------------------------------------------
|Inline stack trace
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|This location contains code that was inlined from union-usage.scala:12
12 | inline if cond then b("hello") else b("goodbye"): Unit
| ^^^^^^^^^^^^
----------------------------------------------------------------------------
-- Deprecation Warning: /home/amarki/snips/union-usage.scala:12:24 -------------
12 | inline if cond then b("hello") else b("goodbye"): Unit
| ^
| method b in object X is deprecated: use f instead for noise suppressionThis might be more intended:
11 | inline if cond then (b("hello"): @nowarn) else ((b("goodbye"): @nowarn): Unit)
| ^^^^^^^^^^^^^^^^^^^^^
|@nowarn annotation does not suppress any warnings but matches a diagnosticExpectation
The intention is to "suppress" -Wnonunit-statement by conditionally inlining : Unit. That doesn't work with the current lint at typer.
Additionally, deprecate the method that is delegated to; it's not desirable to hide it by inlining that body.
That deprecation is suppressed by annotating with nowarn; but the mechanism incurs further warnings.
Metadata
Metadata
Assignees
Labels
area:lintingLinting warnings enabled with -W or -XlintLinting warnings enabled with -W or -Xlintitype:bug