If uint(x) < 0

204 views
Skip to first unread message

Dave Cheney

unread,
Aug 26, 2014, 6:29:33 PM8/26/14
to golang-dev

Hello,

With the success of the illogical shift CL for go vet, is there any interest in adding a check for a condition like x < 0 when x is declared to be unsigned?

Any takers?

Dave

Rob Pike

unread,
Aug 26, 2014, 6:50:25 PM8/26/14
to Dave Cheney, golang-dev
The compiler should take care of that. It's a static error.

-rob
> --
> You received this message because you are subscribed to the Google Groups
> "golang-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-dev+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dave Cheney

unread,
Aug 26, 2014, 7:06:20 PM8/26/14
to Rob Pike, golang-dev
The compiler accepts this

http://play.golang.org/p/KNzVT9fyPW

So if x started as an int, and was later redefined as uint, then the
branch is never taken.

Rob Pike

unread,
Aug 26, 2014, 7:33:59 PM8/26/14
to Dave Cheney, golang-dev
The key word in my mail was "should".

-rob

Dave Cheney

unread,
Aug 26, 2014, 7:38:22 PM8/26/14
to Rob Pike, golang-dev
Whoops, that was my mistake.

I'll check to see if there is already an issue for this and if not open one.

Thanks

Dave
Reply all
Reply to author
Forward
0 new messages