Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

BUG: uint (i.e. uint32) compared to 1 << 62 #227

Closed
rudolph9 opened this issue Dec 13, 2019 · 3 comments
Closed

BUG: uint (i.e. uint32) compared to 1 << 62 #227

rudolph9 opened this issue Dec 13, 2019 · 3 comments

Comments

@rudolph9
Copy link
Contributor

rudolph9 commented Dec 13, 2019

I came across this when v0.0.15 wouldn't compile with gopherjs
This check

I've filed an issue with gopherjs since technically it compiles in go but not gopherjs.

But, it seems like an oversight in the cue impl since i is a uint uint from the received context will never be greater than 1<<32 and branch based on the conditional would never be executed. I believe it's akin to an if false branch...

Perhaps I am mistaken through and it does serve the intended purpose, if that is the case could we adjust the impl from

1850: if i > 1<<62 {

to

1850: if uint64(i) > uint64(1)<<62 {

to work around the bug in gopherjs and help support the npm cuelang package

rudolph9 added a commit to rudolph9/lang-js that referenced this issue Dec 13, 2019
Cue release v0.0.15 with a small work around for an overflow error
see cuelang/cue#227
@mpvl
Copy link
Contributor

mpvl commented Dec 16, 2019

Could you try if changing the return type for uint() from uint to uint64? (And similarly that for int()frominttoint64`)? That should fix it.

@rudolph9
Copy link
Contributor Author

rudolph9 commented Dec 16, 2019

@mpvl If I'm understanding you correctly

(And similarly that for int()frominttoint64`)?

Is referring to the argument passed to Bit here

Which results in an error:

$ gopherjs build -o ./build/__CUE__.js ./src/cue.go
../../../.golang/src/cuelang.org/go/cue/builtins.go:1853:20: cannot use int64(i) (value of type int64) as int value in argument to x.Bit

https://golang.org/pkg/math/big/#Int.Bit


 cue/builtins.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cue/builtins.go b/cue/builtins.go
index 5305379..1a3772a 100644
--- a/cue/builtins.go
+++ b/cue/builtins.go
@@ -1844,13 +1844,13 @@ var builtinPackages = map[string]*builtinPkg{
                        Params: []kind{intKind, intKind},
                        Result: intKind,
                        Func: func(c *callCtxt) {
-                               x, i := c.bigInt(0), c.uint(1)
+                               x, i := c.bigInt(0), c.uint64(1)
                                if c.do() {
                                        c.ret, c.err = func() (interface{}, error) {
                                                if i > 1<<62 {
                                                        return 0, fmt.Errorf("bit index too large")
                                                }
-                                               return x.Bit(int(i)), nil
+                                               return x.Bit(int64(i)), nil
                                        }()
                                }
                        },

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#227.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants