From 9a3bc51c8119cde353da5c304b4c52f348ad7c46 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Sat, 29 Sep 2012 23:23:56 +0800 Subject: [PATCH] test/fixedbugs/bug454.go: add a test for CL 6564052 Also mention that ignoring second blank identifier of range is required by the spec in the code. Fixes #4173. R=daniel.morsing, remyoudompheng, r CC=golang-dev https://golang.org/cl/6594043 --- src/cmd/gc/range.c | 6 +++++- test/fixedbugs/bug454.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/bug454.go diff --git a/src/cmd/gc/range.c b/src/cmd/gc/range.c index 741a9ac9a7..50c4617c06 100644 --- a/src/cmd/gc/range.c +++ b/src/cmd/gc/range.c @@ -71,7 +71,11 @@ typecheckrange(Node *n) v2 = N; if(n->list->next) v2 = n->list->next->n; - + + // this is not only a optimization but also a requirement in the spec. + // "if the second iteration variable is the blank identifier, the range + // clause is equivalent to the same clause with only the first variable + // present." if(isblank(v2)) { n->list = list1(v1); v2 = N; diff --git a/test/fixedbugs/bug454.go b/test/fixedbugs/bug454.go new file mode 100644 index 0000000000..a10abba8b2 --- /dev/null +++ b/test/fixedbugs/bug454.go @@ -0,0 +1,21 @@ +// run + +// 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 4173 + +package main + +func main() { + var arr *[10]int + s := 0 + for i, _ := range arr { + // used to panic trying to access arr[i] + s += i + } + if s != 45 { + println("BUG") + } +} -- 2.48.1