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

Java backend: Unboxed bool return type in trait implementations #6094

Open
eivindfjeldstad opened this issue Feb 4, 2025 · 0 comments
Open
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

Comments

@eivindfjeldstad
Copy link

eivindfjeldstad commented Feb 4, 2025

Dafny version

4.9.1

Code to produce this issue

test.dfy:

module Test {
  trait Something<T> {
    function hey(): T
  }

  datatype Broken extends Something<bool> = create(value: bool) {
    function hey(): bool {
      value
    }
  }
}

Command to run and resulting output

Running

dafny build test.dfy --general-traits=datatype --target:java

fails with

Dafny program verifier finished with 1 verified, 0 errors
/test-java/Test/Broken.java:7: error: Broken is not abstract and does not override abstract method hey() in Something
public class Broken implements Something<Boolean> {
       ^
/test-java/Test/Broken.java:57: error: hey() in Broken cannot implement hey() in Something
  public boolean hey() {
                 ^
  return type boolean is not compatible with Boolean
  where T is a type-variable:
    T extends Object declared in interface Something
2 errors
Error while compiling Java files. Process exited with exit code 1

What happened?

When compiling a Dafny datatype that implements a generic trait with bool as the type argument, the resulting Java code uses a primitive return type where a boxed type is required.

What type of operating system are you experiencing the problem on?

Mac

@eivindfjeldstad eivindfjeldstad added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
Projects
None yet
Development

No branches or pull requests

1 participant