Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading Unreachable case report in ensuring. Bug or feature? #22615

Open
martinberger opened this issue Feb 16, 2025 · 2 comments
Open

Misleading Unreachable case report in ensuring. Bug or feature? #22615

martinberger opened this issue Feb 16, 2025 · 2 comments
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:cannot reproduce stat:needs minimization Needs a self contained minimization

Comments

@martinberger
Copy link

martinberger commented Feb 16, 2025

Compiler version

scalac 3.6.3

sbt: 1.10.7 with the following options in build.sbt:

scalacOptions ++= Seq(
  "-language:strictEquality", 
  "-deprecation",  
  "-explain",  
  "-explain-types",  
  "-feature", 
  "-indent", 
  "-new-syntax",  
  "-print-lines", 
  "-unchecked",  
  "-Xkind-projector", 
  "-Xmigration", 
  "-source:3.7"  
)

Minimized example

def f(n: Int): Option[Int] = {
    if n == 0 then None else Some(n)
} ensuring (
  _ match {
      case Some(i) => i != 0
      case None    => true
  }
)

Output Error/Warning message

sbt:Martin Berger> ~compile
[info] compiling 12 Scala sources to  ...
[warn] -- [E030] Match case Unreachable Warning: .../Main.scala:45:9 
[warn] 45 |    case None      => true
[warn]    |         ^^^^
[warn]    |         Unreachable case
[warn] one warning found

Note: I get this warning only when compiling with sbt. If I compile with scalac -Wall there is no warning!

Why this Error/Warning was not helpful

The message Unreachable case is unhelpful because the None case in the ensuring construct is in fact reachable. This can easily be seen by replacing case None => true with case None => { assert(false); true } and call f(0).

Suggested improvement

I think this is a bug in the type-inferencer. I did not file a bug report, because I wasn't sure if I had not overlooked some subtle feature of the typing system.

@martinberger martinberger added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 16, 2025
@som-snytt
Copy link
Contributor

I could not reproduce it. Are there sbt plugins involved?

Your example says compiling 12 Scala sources, so there are at least eleven more sources involved.

You could link to a sample project.

@martinberger
Copy link
Author

There are no sbt plugins involved. The additional sources should not be relevant, but when I tried in an empty sbt project just now, I could also not reproduce the behaviour. Let me try to minimise my whole 12-file project and see what is causing this behaviour.

@Gedochao Gedochao added stat:cannot reproduce area:pattern-matching stat:needs minimization Needs a self contained minimization and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:pattern-matching area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:cannot reproduce stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

No branches or pull requests

3 participants