From 1947960a6f87437cb3da4fd9341c0d265ff71cf6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9my=20Oudompheng?= Date: Sat, 15 Dec 2012 19:37:59 +0100 Subject: [PATCH] cmd/gc: fix defaultlit of shifts used in interface context. Fixes #4545. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/6937058 --- src/cmd/gc/const.c | 5 +++++ test/fixedbugs/issue4545.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/fixedbugs/issue4545.go diff --git a/src/cmd/gc/const.c b/src/cmd/gc/const.c index 5720efc8e9..31ea3a251c 100644 --- a/src/cmd/gc/const.c +++ b/src/cmd/gc/const.c @@ -1052,6 +1052,11 @@ defaultlit(Node **np, Type *t) // When compiling x := 1<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); diff --git a/test/fixedbugs/issue4545.go b/test/fixedbugs/issue4545.go new file mode 100644 index 0000000000..3f2de16d20 --- /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<