-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gnovm): align Gno constant handling with Go specifications
- Loading branch information
Showing
14 changed files
with
323 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
const t []string = []string{} | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const23.gno:6:8: [](const-type string){} (variable of type []string) is not constant |
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,76 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func main() { | ||
const a int = 1_000_000 | ||
const b byte = byte(1) | ||
const c float64 = 1_000_000.000 | ||
const d string = "Hello, World!" | ||
const e rune = 'a' | ||
const g bool = true | ||
const h uint = 1_000 | ||
const i int8 = 1 | ||
const j int16 = 1 | ||
const k int32 = 1 | ||
const l int64 = 1 | ||
const m uint8 = 1 | ||
const n uint16 = 1 | ||
const o uint32 = 1 | ||
const p uint64 = 1 | ||
const r float32 = 1_000_000.000 | ||
const s = r | ||
const t = len("s") | ||
const u = 1 + len("s") + 3 | ||
ars := [10]string{} | ||
const v = len(ars) | ||
const w = cap(ars) | ||
|
||
fmt.Println(a) | ||
fmt.Println(b) | ||
fmt.Println(c) | ||
fmt.Println(d) | ||
fmt.Println(e) | ||
fmt.Println(g) | ||
fmt.Println(h) | ||
fmt.Println(i) | ||
fmt.Println(j) | ||
fmt.Println(k) | ||
fmt.Println(l) | ||
fmt.Println(m) | ||
fmt.Println(n) | ||
fmt.Println(o) | ||
fmt.Println(p) | ||
fmt.Println(r) | ||
fmt.Println(s) | ||
fmt.Println(t) | ||
fmt.Println(u) | ||
fmt.Println(v) | ||
fmt.Println(w) | ||
} | ||
|
||
// Output: | ||
// 1000000 | ||
// 1 | ||
// 1e+06 | ||
// Hello, World! | ||
// 97 | ||
// true | ||
// 1000 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1e+06 | ||
// 1e+06 | ||
// 1 | ||
// 5 | ||
// 10 | ||
// 10 |
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,11 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
const t = []string{"1"} | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const25.gno:6:8: [](const-type string){(const ("1" string))} (variable of type []string) is not constant |
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 | ||
|
||
import "fmt" | ||
|
||
func v() string { | ||
return "" | ||
} | ||
|
||
func main() { | ||
const t = v() | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const26.gno:10:8: v<VPBlock(3,0)>() (value of type string) is not constant |
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 | ||
|
||
import "fmt" | ||
|
||
func v() string { | ||
return "" | ||
} | ||
|
||
func main() { | ||
var i interface{} = 1 | ||
const t, ok = i.(int) | ||
fmt.Println(t, ok) | ||
} | ||
|
||
// Error: | ||
// main/files/const27.gno:11:8: i<VPBlock(1,0)>.((const-type int)) (comma, ok expression of type (const-type int)) is not constant |
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,12 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
var s []string = []string{"1"} | ||
const t, ok = s[0] | ||
fmt.Println(t, ok) | ||
} | ||
|
||
// Error: | ||
// main/files/const28.gno:7:8: s<VPBlock(1,0)>[(const (0 int))] (variable of type s<VPBlock(1,0)>) is not constant |
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,12 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
s := "1" | ||
const t = s | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const29.gno:7:8: s (variable of type string) is not constant |
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 | ||
|
||
import "fmt" | ||
|
||
func v() { | ||
return | ||
} | ||
|
||
func main() { | ||
const t = v() | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const30.gno:10:8: v<VPBlock(3,0)>() (no value) used as value |
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 | ||
|
||
import "fmt" | ||
|
||
func v() (string, string) { | ||
return "", "" | ||
} | ||
|
||
func main() { | ||
const t, v = v() | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const31.gno:10:8: multiple-value (const (v func()( string, string)))() (value of type [string string]) in single-value context |
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,11 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
const t = 1 + 2 + len([]string{}) | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const32.gno:6:8: [](const-type string){} (variable of type []string) is not constant |