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

Incorrect C# compilation of discriminators with underscores #1607

Closed
jaylorch opened this issue Nov 24, 2021 · 0 comments · Fixed by #1608
Closed

Incorrect C# compilation of discriminators with underscores #1607

jaylorch opened this issue Nov 24, 2021 · 0 comments · Fixed by #1608
Assignees
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label lang: c# Dafny's C# transpiler and its runtime

Comments

@jaylorch
Copy link
Collaborator

If a discriminator has an underscore in it, Dafny generates invalid C# code. The method name will have that underscore replaced with two underscores, but any call to that method will have the underscore unchanged. This problem doesn't exist in Dafny release 3.2.0, but does exist in 3.3.0 and in the current version.

One can reproduce this and get the following error:

(1876,15): error CS1061: 'D' does not contain a definition for 'is_D_1' and no accessible extension method 'is_D_1' accepting a first argument of type 'D' could be found (are you missing a using directive or an assembly reference?)

by running Dafny on a file with the following contents:

module M {
  datatype D = D_1(i: int) | D_2(b: bool)

  method DoIt (d: D)
  {
    if (d.D_1?) {
      print d.i;
    }
    else {
      print d.b;
    }
  }
}

Running Dafny with /spillTargetCode:3 further illuminates the issue. One can see that the method is defined as:

    public bool is_D__1 { get { return this is D_D__1; } }

but the call to that method is:

      if ((d).is_D_1) {
@jaylorch jaylorch added kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label lang: c# Dafny's C# transpiler and its runtime labels Nov 24, 2021
@fabiomadge fabiomadge self-assigned this Nov 25, 2021
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 lang: c# Dafny's C# transpiler and its runtime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants