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

Restrictive type in pattern causes malformed target code #3922

Closed
RustanLeino opened this issue Apr 28, 2023 · 0 comments · Fixed by #3909
Closed

Restrictive type in pattern causes malformed target code #3922

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

Comments

@RustanLeino
Copy link
Collaborator

Dafny version

4.0.0

Code to produce this issue

datatype Record = Record(o: object)

class C { }

method M(r: Record)
  requires r.o is C
{
  match r
  case Record(c: C) =>
}

Command to run and resulting output

% dafny run test.dfy

Dafny program verifier finished with 1 verified, 0 errors
Errors compiling program into test
(5068,18): error CS0266: Cannot implicitly convert type 'object' to '_module.C'. An explicit conversion exists (are you missing a cast?)

What happened?

The example above goes through both the resolver and verifier. Alas, the C# and Java backends do not generate correct code for it.

One possibility would be to fix the C# and Java compilers. However, eventually, we anticipate a new "type case" feature (see #1715). Therefore, a viable solution to the problem above would be to forbid, already in the type system, the use of classes/traits where the source type has a parent trait thereof.

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

Mac

@RustanLeino RustanLeino added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Apr 28, 2023
@RustanLeino RustanLeino self-assigned this Apr 28, 2023
RustanLeino added a commit to RustanLeino/dafny that referenced this issue Apr 29, 2023
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.

1 participant