gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
860 stars 348 forks source link

Doesn't recognize Octal numbers that don't contain an `o` #1322

Closed notJoon closed 4 months ago

notJoon commented 8 months ago

Description

There are two ways to represent octal numbers in Go: as a nunber, like 012345, and by typing the letter o to indicate that value is an octal, like 0o12345.

However, gnolang only recognizes the latter case.

For example:

package main

import "fmt"

func main() {
    octval := 0o12345
    fmt.Println(octval)
}

// Output:
// 5349

In this case, it recognizes the 0o12345 as octal well and prints the result 5349. But, if changes the code like below, It throws an error.

package main

import "fmt"

func main() {
    octval := 012345. // No `o`
    fmt.Println(octval)
}

// error: invalid integer constant: 012345
// Must print 5349

expected behavior:

go oct

My guess is that this problem will be fixed by modifying the scanner file or op_eval.

thehowl commented 8 months ago

My guess is that this problem will be fixed by modifying the scanner file or op_eval.

Yes, if you want to take a stab at it, I suggest changing this part of op_eval and making it treat x.Values that start with 0 to be octals.