Skip to content

Commit 3949faf

Browse files
test: add test that was miscompiled by gccgo
For #49512 Change-Id: Ic08652a4ec611b27150bf10b1118c1395715e5d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/363156 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
1 parent 4d06839 commit 3949faf

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/fixedbugs/issue49512.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// run
2+
3+
// Copyright 2021 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+
7+
package main
8+
9+
type S struct{
10+
m1Called, m2Called bool
11+
}
12+
13+
func (s *S) M1(int) (int, int) {
14+
s.m1Called = true
15+
return 0, 0
16+
}
17+
18+
func (s *S) M2(int) (int, int) {
19+
s.m2Called = true
20+
return 0, 0
21+
}
22+
23+
type C struct {
24+
calls []func(int) (int, int)
25+
}
26+
27+
func makeC() Funcs {
28+
return &C{}
29+
}
30+
31+
func (c *C) Add(fn func(int) (int, int)) Funcs {
32+
c.calls = append(c.calls, fn)
33+
return c
34+
}
35+
36+
func (c *C) Call() {
37+
for _, fn := range c.calls {
38+
fn(0)
39+
}
40+
}
41+
42+
type Funcs interface {
43+
Add(func(int) (int, int)) Funcs
44+
Call()
45+
}
46+
47+
func main() {
48+
s := &S{}
49+
c := makeC().Add(s.M1).Add(s.M2)
50+
c.Call()
51+
if !s.m1Called || !s.m2Called {
52+
panic("missed method call")
53+
}
54+
}

0 commit comments

Comments
 (0)