Skip to content

Bugfix: Message in assert statement needs to wrapped in a Struct in function contract hooks. - #1555

Merged
monal merged 2 commits into
model-checking:features/function-contractsfrom
monal:contract-hook-bugfix
Aug 19, 2022
Merged

monal merged 2 commits into
model-checking:features/function-contractsfrom
monal:contract-hook-bugfix

Conversation

@monal

@monal monal commented Aug 18, 2022

Copy link
Copy Markdown

Description of changes:

Resolves bugfix introduced in #1511.

The following change was introduced in the earlier PR. However, the Expr::string_constant needs to be wrapped in a Struct. Else the extract_const_message function returns a None while handling the assert statement and the compiler panics.

fn handle (/*args*/) {
    if tcx.queries.get_enforce_contracts() {
      fargs.add(Expr::string_constant("Post-condition failed");
      Assert::handle(tcx, instance, fargs, assign_to, target, span);
    } else {
      Assume::handle(tcx, instance, fargs, assign_to, target, span);
    }
  }

Resolved issues:

Resolves bug introduced by #1511

Call-outs:

Testing:

  • How is this change tested?
    Locally tested.

  • Is this a refactor change?
    No,

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@monal
monal requested a review from a team as a code owner August 18, 2022 23:57

@zhassan-aws zhassan-aws left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we


if tcx.queries.get_enforce_contracts() {
fargs.push(Expr::string_constant("Post-condition failed"));
let msg = Expr::string_constant("Post-condition failed");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we wrap this in a helper function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@monal
monal merged commit 0c1b45b into model-checking:features/function-contracts Aug 19, 2022
@monal
monal deleted the contract-hook-bugfix branch August 19, 2022 15:07
zhassan-aws pushed a commit to zhassan-aws/kani that referenced this pull request May 26, 2023
…unction contract hooks. (model-checking#1555)

* Bugfix for msg in assert

* Add helper function

Co-authored-by: Monal Narasimhamurthy <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants