scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Errors from compiler warnings don't make compilation process fail

Open prolativ opened this issue 7 months ago • 6 comments

Version(s) 1.8.1

Describe the bug Compilation errors originating from warnings do not fail the compilation process when compiling with bloop

To Reproduce

//> using scala 3.7.0
//> using options -Werror -Wunused:all

def foo =
  val x = 1
  2

scala-cli compile .

Expected behaviour The exit code should NOT be 0. The problem does not occur when compiling with --server=false

prolativ avatar Jun 10 '25 07:06 prolativ

Huh... this can be observerd with Scala 2.13 and 2.12 (with -Xfatal-warnings) as well.

//> using scala 2.12
//> using options -Xfatal-warnings -Ywarn-unused:_

object Something {
  def foo = {
    val x = 1
    2
  }
}

and

//> using scala 2.13
//> using options -Werror -Wunused

object Something {
  def foo = {
    val x = 1
    2
  }
}

Gedochao avatar Jun 10 '25 08:06 Gedochao

What's interesting, this still fails when we try to run... but we don't run with Bloop, we just build with it. As far as I can tell, we're getting status code 0 from Bloop's buildTargetCompile endpoint, so Bloop claims everything is fine.

https://github.com/VirtusLab/scala-cli/blob/815fb5d4c1bc29023a5e09159d55f82bb2bf720e/modules/build/src/main/scala/scala/build/Bloop.scala#L53-L57

I'd say need to investigate upstream. cc @tgodzik

Gedochao avatar Jun 10 '25 08:06 Gedochao

Added integration tests with the reproduction for all Scala versions in this draft PR:

  • https://github.com/VirtusLab/scala-cli/pull/3736

Gedochao avatar Jun 10 '25 08:06 Gedochao

I think the issue might be that in Bloop we remove the flag, and later turn all warnings to errors manually. This is to always get proper artefacts for Metals etc. generated.

tgodzik avatar Jun 10 '25 17:06 tgodzik

just found this caveat 😅

Is there another way to find out if a scala-cli compile / package had warnings, other than parsing STDERR?

kubukoz avatar Jul 07 '25 21:07 kubukoz

Is there another way to find out if a scala-cli compile / package had warnings, other than parsing STDERR?

...not really.

Gedochao avatar Jul 08 '25 06:07 Gedochao