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

Clash when compiling a datatype containing a static const Default #3809

Closed
mschlaipfer opened this issue Mar 28, 2023 · 0 comments · Fixed by #6031
Closed

Clash when compiling a datatype containing a static const Default #3809

mschlaipfer opened this issue Mar 28, 2023 · 0 comments · Fixed by #6031
Assignees
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

Comments

@mschlaipfer
Copy link
Member

mschlaipfer commented Mar 28, 2023

Dafny version

4.0.0.50303

Code to produce this issue

module m {
  datatype D = A
             | B
             | C {
    static const Default: D := A
  }
}

Command to run and resulting output

$ dafny build -t java bug.dfy

Dafny program verifier finished with 0 verified, 0 errors
<snip>/bug-java/m_Compile/D.java:37: error: method Default() is already defined in class D
  public static D Default()
                  ^
1 error
Error while compiling Java files. Process exited with exit code 1

What happened?

Dafny seems to codegen a Default method for datatypes, but does not check if there is a user-defined one. When defining Default ourselves there's a clash.

$ cat <snip>/bug-java/m_Compile/D.java
// Class D
// Dafny class D compiled into Java
package m_Compile;


@SuppressWarnings({"unchecked", "deprecation"})
public abstract class D {
  public D() { }

  private static final D theDefault = m_Compile.D.create_A();
  public static D Default() {
    return theDefault;
  }

// ...

  public static D Default()
  {
    return m_Compile.D.create_A();
  }
}

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

Mac

@mschlaipfer mschlaipfer added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Mar 28, 2023
@olivier-aws olivier-aws self-assigned this Jan 8, 2025
@olivier-aws olivier-aws linked a pull request Jan 13, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants