FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
cmd/gc: fix defaultlit of shifts used in interface context.

Fixes issue 4545.

Please review this at https://codereview.appspot.com/6937058/

Affected files:
M src/cmd/gc/const.c
A test/fixedbugs/issue4545.go


Index: src/cmd/gc/const.c
===================================================================
--- a/src/cmd/gc/const.c
+++ b/src/cmd/gc/const.c
@@ -1052,6 +1052,11 @@
// When compiling x := 1<<i + 3.14, this means we try to push
// the float64 down into the 1<<i, producing the correct error
// (cannot shift float64).
+ //
+ // If t is an interface type, we want the default type for the
+ // value, so just do as if no type was given.
+ if(t && t->etype == TINTER)
+ t = T;
if(t == T && (n->right->op == OLSH || n->right->op == ORSH)) {
defaultlit(&n->left, T);
defaultlit(&n->right, n->left->type);
Index: test/fixedbugs/issue4545.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/fixedbugs/issue4545.go
@@ -0,0 +1,19 @@
+// errorcheck
+
+// Copyright 2012 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 4545: untyped constants are incorrectly coerced
+// to concrete types when used in interface{} context.
+
+package main
+
+import "fmt"
+
+func main() {
+ var s uint
+ fmt.Println(1.0 + 1<<s) // ERROR "invalid operation"
+ x := 1.0 + 1<<s // ERROR "invalid operation"
+ _ = x
+}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 14, '12 at 11:27p
activeDec 15, '12 at 6:38p
posts3
users2
websitegolang.org

2 users in discussion

Remyoudompheng: 2 posts Russ Cox: 1 post

People

Translate

site design / logo © 2022 Grokbase