-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds support for method receivers of ghost pointer type, minimizes diff
- Loading branch information
Showing
10 changed files
with
96 additions
and
18 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
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
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
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
32 changes: 32 additions & 0 deletions
32
src/test/resources/regressions/features/ghost_pointer/ghost-pointer-receiver-fail01.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,32 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
package GhostPointerReceiverFail01 | ||
|
||
type Foo struct { | ||
field int | ||
} | ||
|
||
ghost | ||
decreases | ||
func GhostFunc() { | ||
p := &Foo{ 42 } | ||
p.bar1() | ||
//:: ExpectedOutput(type_error) | ||
p.bar2() // bar2 is not defined on a ghost pointer | ||
} | ||
|
||
decreases | ||
//:: ExpectedOutput(type_error) | ||
func (r gpointer[Foo]) bar1() int { // ghostpointer is only allowed for ghost methods | ||
r.field = 0 | ||
return 42 | ||
} | ||
|
||
ghost | ||
decreases | ||
func (r *Foo) bar2() int { | ||
//:: ExpectedOutput(type_error) | ||
r.field = 0 // fails since we're trying to modify actual memory | ||
return r.field | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/resources/regressions/features/ghost_pointer/ghost-pointer-receiver-simple01.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,47 @@ | ||
// Any copyright is dedicated to the Public Domain. | ||
// http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
package GhostPointerReceiverSimple01 | ||
|
||
type Foo struct { | ||
field int | ||
} | ||
|
||
ghost | ||
decreases | ||
preserves acc(p) | ||
func GhostFunc(p *Foo) { | ||
gp := &Foo{ 42 } | ||
gp.bar1() | ||
|
||
p.bar2() | ||
(*p).bar3() | ||
(*gp).bar3() | ||
} | ||
|
||
ghost | ||
decreases | ||
preserves acc(r) | ||
func (r gpointer[Foo]) bar1() int { | ||
r.field = 0 | ||
return r.field | ||
} | ||
|
||
decreases | ||
preserves acc(r) | ||
func (r *Foo) bar2() int { | ||
r.field = 0 | ||
return r.field | ||
} | ||
|
||
ghost | ||
decreases | ||
func (r Foo) bar3() int { | ||
r.field = 42 | ||
return r.field | ||
} | ||
|
||
func (r Foo) bar4() int { | ||
r.field = 42 | ||
return r.field | ||
} |