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

Missing downcasts #5597

Closed
RustanLeino opened this issue Jul 4, 2024 · 0 comments · Fixed by #5589
Closed

Missing downcasts #5597

RustanLeino opened this issue Jul 4, 2024 · 0 comments · Fixed by #5589
Assignees
Labels
invalid translated code The compiler generates invalid code, making the the target language infrastructure crash kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label

Comments

@RustanLeino
Copy link
Collaborator

Dafny version

4.7.0

Code to produce this issue

method Main() {
  var n: set<Number> := {};
  var s: set<Integer>;
  s := DoItWithAssignment(n);
  print |s|, " ";
  s := DoItWithPlainLet(n);
  print |s|, " ";
  s := DoItWithOptimizedLet(n);
  print |s|, " ";
  s := DoItViaFunctionBodyResult(n);
  print |s|, "\n";
}

trait Number {
  const value: int
}

class Integer extends Number {
  constructor(value: int) {
    this.value := value;
  }
}

method DoItWithAssignment(numbers: set<Number>) returns (integers00: set<Integer>)
  requires |numbers| == 0
{
  integers00 := numbers;
}

function DoItWithPlainLet(numbers: set<Number>): set<Integer>
  requires |numbers| == 0
{
  {} +
  var integers11: set<Integer> := numbers;
  integers11
}

function DoItWithOptimizedLet(numbers: set<Number>): set<Integer>
  requires |numbers| == 0
{
  var integers22: set<Integer> := numbers;
  integers22
}

function DoItViaFunctionBodyResult(numbers: set<Number>): set<Integer>
  requires |numbers| == 0
{
  numbers
}

Command to run and resulting output

% dafny run test.dfy

Dafny program verifier finished with 5 verified, 0 errors
Errors compiling program into test
source(5770,43): error CS0266: Cannot implicitly convert type 'Dafny.ISet<_module.Number>' to 'Dafny.ISet<_module.Integer>'. An explicit conversion exists (are you missing a cast?)

source(5774,14): error CS0266: Cannot implicitly convert type 'Dafny.ISet<_module.Number>' to 'Dafny.ISet<_module.Integer>'. An explicit conversion exists (are you missing a cast?)

What happened?

Dafny emits malformed code for the bodies of DoItWithOptimizedLet and DoItViaFunctionBodyResult.

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

Mac

@RustanLeino RustanLeino added kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label invalid translated code The compiler generates invalid code, making the the target language infrastructure crash labels Jul 4, 2024
@RustanLeino RustanLeino self-assigned this Jul 4, 2024
RustanLeino added a commit to RustanLeino/dafny that referenced this issue Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid translated code The compiler generates invalid code, making the the target language infrastructure crash 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