From 8073f99ea301848ccf66152c6fb10ff8fd3b86b4 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 7 Jun 2017 11:32:42 -0700 Subject: [PATCH] go/types: adjust type-checking of shifts to match compilers For #14822. Change-Id: Ia3f5558f3e0dcb8ee2dab54a6e9588eecc22511f Reviewed-on: https://go-review.googlesource.com/45074 Reviewed-by: Alan Donovan --- src/go/types/expr.go | 6 +++--- src/go/types/testdata/shifts.src | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 7f54b09071..1624858329 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -633,13 +633,13 @@ func (check *Checker) shift(x, y *operand, e *ast.BinaryExpr, op token.Token) { } // spec: "The right operand in a shift expression must have unsigned - // integer type or be an untyped constant that can be converted to - // unsigned integer type." + // integer type or be an untyped constant representable by a value of + // type uint." switch { case isUnsigned(y.typ): // nothing to do case isUntyped(y.typ): - check.convertUntyped(y, Typ[UntypedInt]) + check.convertUntyped(y, Typ[Uint]) if y.mode == invalid { x.mode = invalid return diff --git a/src/go/types/testdata/shifts.src b/src/go/types/testdata/shifts.src index 099c9ecc7c..dc029fc647 100644 --- a/src/go/types/testdata/shifts.src +++ b/src/go/types/testdata/shifts.src @@ -10,7 +10,7 @@ func shifts0() { s = 10 _ = 0<<0 _ = 1<> 1.1 /* ERROR "must be unsigned integer" */ // example from issue 11325 - _ = 0 >> 1.1 /* ERROR "must be unsigned integer" */ - _ = 0 << 1.1 /* ERROR "must be unsigned integer" */ + var _ = 0 >> 1.1 /* ERROR "truncated to uint" */ // example from issue 11325 + _ = 0 >> 1.1 /* ERROR "truncated to uint" */ + _ = 0 << 1.1 /* ERROR "truncated to uint" */ _ = 0 >> 1. - _ = 1 >> 1.1 /* ERROR "must be unsigned integer" */ + _ = 1 >> 1.1 /* ERROR "truncated to uint" */ _ = 1 >> 1. _ = 1. >> 1 _ = 1. >> 1. -- 2.50.0