-
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
11 changed files
with
250 additions
and
0 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
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: invalid constant type []string |
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,67 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
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 = min(i, min(1, 3)) | ||
const v = max(i, max(1, 3)) | ||
const w = min(i, max(1, 3)) + max(i, min(1, 3)) + 3 | ||
const x+=w | ||
|
||
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) | ||
} | ||
|
||
// Output: | ||
// 1000000 | ||
// 1 | ||
// 1e+06 | ||
// Hello, World! | ||
// 97 | ||
// true | ||
// 1000 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1 | ||
// 1e+06 | ||
// 1e+06 | ||
// 1 |
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 (slice[("1" string)] []string)) (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,15 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
func v() string { | ||
return "" | ||
} | ||
|
||
func main() { | ||
const t = v() | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const25.gno:6:8: (const (slice[("1" string)] []string)) (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<VPUverse(0)>.(int<VPUverse(0)>) (comma, ok expression of type int<VPUverse(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() { | ||
var s []string = []string{"1"} | ||
const t, ok = s[0] | ||
fmt.Println(t, ok) | ||
} | ||
|
||
// Error: | ||
// main/files/const25.gno:6:8: (const (slice[("1" string)] []string)) (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,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/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() (string, string) { | ||
return "", "" | ||
} | ||
|
||
func main() { | ||
const t, v = v() | ||
fmt.Println(t) | ||
} | ||
|
||
// Error: | ||
// main/files/const29.gno:7:8: s (variable of type string) is not constant |