Skip to content

Fruitless type test warning in incremental build but not in clean build #12414

@danarmak

Description

@danarmak

reproduction steps

Using either Scala 2.12.14 or 2.13.6, and two source files:

Classes.scala
===========
package testwarning

sealed trait Trait1
sealed trait Trait2

class Class1 extends Trait1
// No class extends Trait1 with Trait2

Tester.scala
=========
package testwarning

object Tester {
  def test(x: Trait1): String = x match {
    case y: Trait2 => "Also Trait2"
    case _ => "Only Trait1"
  }
}

I expect to get the warning:

[warn] /home/danarmak/test/scala-testwarning-repro/src/main/scala/testwarning/Tester.scala:6:13: fruitless type test: a value of type testwarning.Trait1 cannot also be a testwarning.Trait2
[warn]     case y: Trait2 => "Also Trait2"
[warn]             ^

Running sbt clean compile produces no warning. But if I then change Tester.scala (e.g. add some whitespace) and run sbt compile (incrementally), I get the warning. I believe the same happens with the warning "match may not be exhaustive".

Because the reproduction requires two source files, I also uploaded it here with the necessary sbt project.

problem

Incremental compilation and clean / full compilation should produce the same result. And if they don't, then a clean build should be the 'correct' one.

This is interfering with fatal-warnings on my CI, because the CI's clean build doesn't catch the actual warnings. This has also caused a @nowarn annotation does not suppress any warnings error on the CI.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions