From 1fe8fdf7085f52f4060a06e31ae3033163a20394 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Tue, 19 Feb 2013 09:20:56 -0800 Subject: [PATCH] go/types: Use left-hand side's type as hint for right-hand side expression evaluation in assignment operations. R=golang-dev, gri CC=golang-dev https://golang.org/cl/7349046 --- src/pkg/exp/gotype/gotype_test.go | 12 ++++++------ src/pkg/go/types/stmt.go | 4 +++- src/pkg/go/types/testdata/stmt0.src | 5 ++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pkg/exp/gotype/gotype_test.go b/src/pkg/exp/gotype/gotype_test.go index 3fbada7920a..03c114013a6 100644 --- a/src/pkg/exp/gotype/gotype_test.go +++ b/src/pkg/exp/gotype/gotype_test.go @@ -61,7 +61,7 @@ var tests = []string{ "bufio", "bytes", - // "compress/bzip2", + "compress/bzip2", "compress/flate", "compress/gzip", // "compress/lzw", @@ -80,7 +80,7 @@ var tests = []string{ "crypto/elliptic", "crypto/hmac", "crypto/md5", - // "crypto/rand", + "crypto/rand", "crypto/rc4", "crypto/rsa", "crypto/sha1", @@ -126,7 +126,7 @@ var tests = []string{ "go/parser", "go/printer", "go/scanner", - // "go/token", + "go/token", "go/types", "hash/adler32", @@ -138,7 +138,7 @@ var tests = []string{ "image/color", "image/draw", "image/gif", - // "image/jpeg", + "image/jpeg", "image/png", "index/suffixarray", @@ -149,7 +149,7 @@ var tests = []string{ "log", "log/syslog", - // "math", + "math", //"math/big", "math/cmplx", "math/rand", @@ -168,7 +168,7 @@ var tests = []string{ "net/rpc", "net/rpc/jsonrpc", "net/smtp", - // "net/textproto", + "net/textproto", "net/url", "path", diff --git a/src/pkg/go/types/stmt.go b/src/pkg/go/types/stmt.go index 05a65ca2c02..2da798e4ca0 100644 --- a/src/pkg/go/types/stmt.go +++ b/src/pkg/go/types/stmt.go @@ -403,11 +403,13 @@ func (check *checker) stmt(s ast.Stmt) { return } var x, y operand + // The lhs operand's type doesn't need a hint (from the rhs operand), + // because it must be a fully typed variable in this case. check.expr(&x, s.Lhs[0], nil, -1) if x.mode == invalid { return } - check.expr(&y, s.Rhs[0], nil, -1) + check.expr(&y, s.Rhs[0], x.typ, -1) if y.mode == invalid { return } diff --git a/src/pkg/go/types/testdata/stmt0.src b/src/pkg/go/types/testdata/stmt0.src index ca36834fde6..37610d3ddd1 100644 --- a/src/pkg/go/types/testdata/stmt0.src +++ b/src/pkg/go/types/testdata/stmt0.src @@ -29,6 +29,9 @@ func _() { s += "bar" s += 1 /* ERROR "cannot convert.*string" */ + + var u64 uint64 + u64 += 1<