scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.72k stars 1.04k forks source link

Coverage misses expression with `-Yexplicit-nulls` and `.nn` #20507

Open mohe2015 opened 1 month ago

mohe2015 commented 1 month ago

Compiler version

3.4.2 and 3.5.0-RC1, so probably all

Minimized code

With -Yexplicit-nulls and coverage enabled (project available at https://github.com/mohe2015/scala3-broken-coverage-explicit-nulls)

@main def hello(): Unit =
  println("Hello world!".nn)

Output

The expression is not marked as covered:

image

Expectation

All code is covered.

mohe2015 commented 1 month ago

Probably has something to do with inline def in general. Maybe it would make sense to have some annotation to influence this.

mohe2015 commented 1 month ago

Related case is probably

@main def hello(): Unit =
  try {
    assert(true, 1 / 0)
    assert(false, 1 / 1)
  } catch {
    case assertionError: AssertionError => assertionError.printStackTrace()
  }

image where I would argue the 1 / 0 should not be covered at all (white) because as the assertion is true it is not executed but I also think it wouldn't make sense that assertion error messages create missing coverage by default.

mohe2015 commented 1 month ago

Even more cases that may or may not be related. Depending on their root cause they may need a separate issue.

@main def hello(): Unit =
  assert(1 + 1 == 2 + 0)
  assert(true)
  assert(1 < 2)
  assert(Boolean.box(1 == 1))
  assert("hello".size == 5)

image