-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/resources/regressions/features/interfaces/ghostnessOfImplementation-fail1.gobra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
// this test makes sure that a method's implementation has the same ghostness as specified in the interface | ||
|
||
package pkg | ||
|
||
type itfWithActualMethod interface { | ||
decreases | ||
actualMethod() int | ||
} | ||
|
||
type itfWithActualPureMethod interface { | ||
decreases | ||
pure actualPureMethod() int | ||
} | ||
|
||
type itfWithGhostMethod interface { | ||
ghost | ||
decreases | ||
ghostMethod() int | ||
} | ||
|
||
type itfWithGhostPureMethod interface { | ||
ghost | ||
decreases | ||
pure ghostPureMethod() int | ||
} | ||
|
||
type someImplementation struct { | ||
value int | ||
} | ||
|
||
// checks that `someImplementation` is indeed considered an implementation of each interface, i.e., that the ghost | ||
// attribute in the interface and implementation is correctly handled. | ||
//:: ExpectedOutput(type_error) | ||
*someImplementation implements itfWithActualMethod | ||
//:: ExpectedOutput(type_error) | ||
*someImplementation implements itfWithActualPureMethod | ||
//:: ExpectedOutput(type_error) | ||
*someImplementation implements itfWithGhostMethod | ||
//:: ExpectedOutput(type_error) | ||
*someImplementation implements itfWithGhostPureMethod | ||
|
||
ghost | ||
decreases | ||
func (impl *someImplementation) actualMethod() int { | ||
return 42 | ||
} | ||
|
||
ghost | ||
decreases | ||
pure func (impl *someImplementation) actualPureMethod() int { | ||
return 42 | ||
} | ||
|
||
decreases | ||
func (impl *someImplementation) ghostMethod() int { | ||
return 42 | ||
} | ||
|
||
decreases | ||
pure func (impl *someImplementation) ghostPureMethod() int { | ||
return 42 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
package main | ||
|
||
ghost | ||
decreases x | ||
pure func more(x int) int { | ||
return x <= 0 ? 1 : more(x - 2) + 3 | ||
} | ||
|
||
ghost /* lemma */ | ||
decreases x | ||
ensures x < more(x) | ||
func increasing(x int) | ||
|
||
// returning b (a ghost variable) is not allowed as this is an actual function | ||
//:: ExpectedOutput(type_error) | ||
func exampleLemmaUse(a int) int { | ||
increasing(a) | ||
b := more(a) | ||
c := more(b) | ||
if a < 1000 { | ||
increasing(more(a)) | ||
assert 2 <= c - a | ||
} | ||
assert 2 <= c - a || 200 <= a | ||
return b | ||
} |