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

(Test Generation) stack overflow during test generation related to self-referencing objects #3726

Closed
Dargones opened this issue Mar 10, 2023 · 0 comments · Fixed by #3727
Closed
Labels
kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label part: test generation Relates to the dafny generate-tests command

Comments

@Dargones
Copy link
Collaborator

Dafny version

4.0.0

Code to produce this issue

module M {

    class LoopingList {

        var next:LoopingList;
        var value:int;

        constructor() {
            value := 0;
            next := this;
        }

        method getValue() returns (value:int) {
            return this.value;
        }
    }
}

Command to run and resulting output

dotnet ~/RiderProjects/dafny/Binaries/Dafny.dll generate-tests Block example.dfy

Program terminates with a stack overflow, the following trace causing infinite recursion:


DafnyTestGeneration.TestMethod.GetClassTypeInstance
DafnyTestGeneration.TestMethod.GetDefaultValue
DafnyTestGeneration.TestMethod.GetFieldValue


### What happened?

Field `next` is irrelevant for a counterexample used by test generation and so test generation must figure out by itself the value of this field. It should assign the field of the object to the object itself, producing the test below:

```Dafny
method {:test} test0() {
  var loopingList0 : M.LoopingList := getFreshMLoopingList();
  loopingList0.next := loopingList0;
  loopingList0.value := 12;
  var r0 := loopingList0.getValue();
}

method {:synthesize} getFreshMLoopingList() returns (o:M.LoopingList) ensures fresh(o)

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

Linux

@Dargones Dargones added the kind: bug Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label label Mar 10, 2023
@MikaelMayer MikaelMayer added the part: test generation Relates to the dafny generate-tests command label Mar 13, 2023
atomb added a commit that referenced this issue May 25, 2023
… generation (#3727)

Fixes #3726

This PR fixes a situation in which test generation gets into infinite
recursion when trying to construct a potentially self-referential object
that the verifier gives no information about (see the test, which is
also the example in the linked issue). The main problem was that
existing code compared types by reference in one instance in which a
comparison of the types's string representations should have been used.

By submitting this pull request, I confirm that my contribution
is made under the terms of the MIT license.

---------

Co-authored-by: Aleksandr Fedchin <[email protected]>
Co-authored-by: Aaron Tomb <[email protected]>
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 part: test generation Relates to the dafny generate-tests command
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants