blob: c2382acf13ff5119c7f03f55413785545c4043b7 [file] [log] [blame]
Rémy Oudomphenga85fa332012-08-25 10:16:02 +02001// cmpout
Robert Griesemer82540eb2009-09-10 10:30:36 -07002
3// Copyright 2009 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9import "go/ast";
10
11func g(list []ast.Expr) {
12 n := len(list)-1;
Robert Griesemer5a9ad8b2010-12-06 14:23:18 -080013 println(list[n].Pos());
Robert Griesemer82540eb2009-09-10 10:30:36 -070014}
15
16
17// f is the same as g except that the expression assigned to n is inlined.
18func f(list []ast.Expr) {
19 // n := len(list)-1;
Robert Griesemer5a9ad8b2010-12-06 14:23:18 -080020 println(list[len(list)-1 /* n */].Pos());
Robert Griesemer82540eb2009-09-10 10:30:36 -070021}
22
23
24func main() {
25 list := []ast.Expr{&ast.Ident{}};
26 g(list); // this works
27 f(list); // this doesn't
28}
29
30
31/*
320
33throw: index out of range
34
35panic PC=0x2bcf10
36throw+0x33 /home/gri/go/src/pkg/runtime/runtime.c:71
37 throw(0x470f8, 0x0)
38sys·throwindex+0x1c /home/gri/go/src/pkg/runtime/runtime.c:45
39 sys·throwindex()
40main·f+0x26 /home/gri/go/test/bugs/bug206.go:16
41 main·f(0x2b9560, 0x0)
42main·main+0xc3 /home/gri/go/test/bugs/bug206.go:23
43 main·main()
44mainstart+0xf /home/gri/go/src/pkg/runtime/amd64/asm.s:55
45 mainstart()
46goexit /home/gri/go/src/pkg/runtime/proc.c:133
47 goexit()
48*/