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

exhaustive switch expression is not fully covered #1571

Closed
eortega-pjr opened this issue Jan 25, 2024 · 2 comments
Closed

exhaustive switch expression is not fully covered #1571

eortega-pjr opened this issue Jan 25, 2024 · 2 comments
Labels
declined: duplicate ❌ This issue or pull request already exists

Comments

@eortega-pjr
Copy link

I apologize if the terminology is incorrect. I wasn't getting full coverage on our fully-defined and exercised switch-expressions after upgrading to jacoco-8.11.0.

I extended the original example here: #1472


  • JaCoCo version: 0.8.11.202310140853
  • Operating system: Linux
  • Tool integration: none/javac
java version "21.0.1" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)
  • Complete executable reproducer:
enum Example {
    A, B;

    static void example(Example e) {
        switch (e) {
            case A -> {
                int i = 4;
            }
            case B -> {
                int i = 4;
            }
        }
    }

    public static void main(String[] args) {
        example(A);
        example(B);
    }
}
  • Steps: (what exactly are you doing with the above reproducer?)
javac Example.java -d classes
java -javaagent:jacocoagent.jar -cp classes Example
java -jar jacococli.jar report jacoco.exec --classfiles classes --sourcefiles . --html report

Expected behaviour

Full branch coverage

Actual behaviour

2024-01-24-163922_565x578_scrot

Thanks.

@eortega-pjr eortega-pjr added the type: bug 🐛 Something isn't working label Jan 25, 2024
@Godin
Copy link
Member

Godin commented Jan 25, 2024

This

switch (e) {
	 case A -> {
	 	 int i = 4;
	}
	 case B -> {
	 	 int i = 4;
	}
}

is switch statement and not switch expression. As proof - try to add a new constant to enum and you'll see that the compiler will not complain that switch is not exhaustive.

Duplicates #1531

@Godin Godin closed this as completed Jan 25, 2024
@Godin Godin added declined: duplicate ❌ This issue or pull request already exists and removed type: bug 🐛 Something isn't working labels Jan 25, 2024
@eortega-pjr
Copy link
Author

oh wow

Thanks for the quick response @Godin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declined: duplicate ❌ This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants