Skip to content

Assert for the elephant let-or-fail operator in expressions #1791

Open
@MikaelMayer

Description

@MikaelMayer

It's possible to write the following:

function SubTest(a: int): (r: Result<string, int>)

function Test(): (r: Result<string, int>) {
    var s :- SubTest(3);
    Success(s)
}

but let's say I would like to assert that SubTest won't fail (because of some conditions in the inputs of SubTest).
In methods, it's possible to prefix the call to SubTest with assert, and it will emit the assertion. However, it's not possible for functions yet.

It would be however obvious that

function SubTest(a: int): (r: Result<string, int>)

function Test(): (r: Result<string, int>) {
    var s :- assert SubTest(3);
    Success(s)
}

should be rewritten to:

function SubTest(a: int): (r: Result<bool, int>)

function Test(): (r: Result<string, int>) {
    var tmp := SubTest(3);
    assert !tmp.IsFailure();
    var s := tmp.Extract();
    Success(s);
}

The same goes for the assume and expect keywords, since many users use function methods, might use them for testing, and also to assume something before coming back to it and revisiting the keyword later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: good-first-issueGood first issueskind: enhancementEnhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafnypart: language definitionRelating to the Dafny language definition itselfpart: parserFirst phase of Dafny's pipelinepriority: not yetWill reconsider working on this when we're looking for work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions