-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnovm): prevent cyclic references in type declarations (#2081)
Address #2008. In this pull request, we're implementing a special handling for type declarations to check cynic dependency. Due to their unique nature, we must meticulously search through their fields to identify potential cyclic reference. <details><summary>Contributors' checklist...</summary> - [*] Added new tests, or not needed, or not feasible - [ ] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [ ] Updated the official documentation or not needed - [*] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [ ] Added references to related issues and PRs - [ ] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: deelawn <[email protected]>
- Loading branch information
1 parent
6f7f589
commit 1e0e52c
Showing
28 changed files
with
474 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
const A = B | ||
const B = A + 1 | ||
|
||
func main() { | ||
} | ||
|
||
// Error: | ||
// main/files/circular_constant.gno:3:7: constant definition loop with A |
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,13 @@ | ||
package main | ||
|
||
type S struct { | ||
T S | ||
} | ||
|
||
func main() { | ||
var a, b S | ||
println(a == b) | ||
} | ||
|
||
// Error: | ||
// main/files/recursive1.gno:1:1: invalid recursive type: S -> S |
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,15 @@ | ||
package main | ||
|
||
type S1 *S | ||
|
||
type S struct { | ||
T S1 | ||
} | ||
|
||
func main() { | ||
var a, b S | ||
println(a == b) | ||
} | ||
|
||
// Output: | ||
// true |
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,16 @@ | ||
package main | ||
|
||
type S struct { | ||
T *S | ||
B Integer | ||
} | ||
|
||
type Integer int | ||
|
||
func main() { | ||
var a, b S | ||
println(a == b) | ||
} | ||
|
||
// Output: | ||
// true |
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,17 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type S struct { | ||
A [2][2]S | ||
} | ||
|
||
func main() { | ||
var a, b S | ||
|
||
fmt.Println(a) | ||
fmt.Println(b) | ||
} | ||
|
||
// Error: | ||
// main/files/recursive1c.gno:1:1: invalid recursive type: S -> S |
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,17 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
type S struct { | ||
A [2]S | ||
} | ||
|
||
func main() { | ||
var a, b S | ||
|
||
fmt.Println(a) | ||
fmt.Println(b) | ||
} | ||
|
||
// Error: | ||
// main/files/recursive1d.gno:1:1: invalid recursive type: S -> S |
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,13 @@ | ||
package main | ||
|
||
type S struct { | ||
A [2][]S | ||
} | ||
|
||
func main() { | ||
var a, b S | ||
println(a) | ||
} | ||
|
||
// Output: | ||
// (struct{(array[(nil []main.S),(nil []main.S)] [2][]main.S)} main.S) |
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,13 @@ | ||
package main | ||
|
||
func main() { | ||
type S struct { | ||
T S | ||
} | ||
|
||
var a, b S | ||
println(a == b) | ||
} | ||
|
||
// Error: | ||
// main/files/recursive1f.gno:3:1: invalid recursive type: S -> S |
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,21 @@ | ||
package main | ||
|
||
type A struct { | ||
X B | ||
} | ||
|
||
type B struct { | ||
X C | ||
} | ||
|
||
type C struct { | ||
X A | ||
} | ||
|
||
func main() { | ||
var p, q A | ||
println(p == q) | ||
} | ||
|
||
// Error: | ||
// main/files/recursive2.gno:1:1: invalid recursive type: A -> B -> C -> A |
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,21 @@ | ||
package main | ||
|
||
type A struct { | ||
X B | ||
} | ||
|
||
type B struct { | ||
X int | ||
} | ||
|
||
type C struct { | ||
X A | ||
} | ||
|
||
func main() { | ||
var p, q A | ||
println(p == q) | ||
} | ||
|
||
// Output: | ||
// true |
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,21 @@ | ||
package main | ||
|
||
type A struct { | ||
X B | ||
} | ||
|
||
type B struct { | ||
X C | ||
} | ||
|
||
type C struct { | ||
X *A | ||
} | ||
|
||
func main() { | ||
var p, q A | ||
println(p == q) | ||
} | ||
|
||
// Output: | ||
// true |
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,21 @@ | ||
package main | ||
|
||
func main() { | ||
type A struct { | ||
X B | ||
} | ||
|
||
type B struct { | ||
X C | ||
} | ||
|
||
type C struct { | ||
X A | ||
} | ||
|
||
var p, q A | ||
println(p == q) | ||
} | ||
|
||
// Error: | ||
// main/files/recursive2c.gno:3:1: name B not defined in fileset with files [files/recursive2c.gno] |
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,21 @@ | ||
package main | ||
|
||
type A struct { | ||
X *B | ||
} | ||
|
||
type B struct { | ||
X int | ||
} | ||
|
||
type C struct { | ||
X A | ||
} | ||
|
||
func main() { | ||
var p, q A | ||
println(p == q) | ||
} | ||
|
||
// Output: | ||
// true |
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,13 @@ | ||
package main | ||
|
||
type S struct { | ||
T *S | ||
} | ||
|
||
func main() { | ||
var a, b S | ||
println(a == b) | ||
} | ||
|
||
// Output: | ||
// true |
Oops, something went wrong.