diff options
Diffstat (limited to 'test/fixedbugs/issue59709.dir')
-rw-r--r-- | test/fixedbugs/issue59709.dir/aconfig.go | 10 | ||||
-rw-r--r-- | test/fixedbugs/issue59709.dir/bresource.go | 27 | ||||
-rw-r--r-- | test/fixedbugs/issue59709.dir/cmem.go | 37 | ||||
-rw-r--r-- | test/fixedbugs/issue59709.dir/dcache.go | 39 | ||||
-rw-r--r-- | test/fixedbugs/issue59709.dir/main.go | 17 |
5 files changed, 130 insertions, 0 deletions
diff --git a/test/fixedbugs/issue59709.dir/aconfig.go b/test/fixedbugs/issue59709.dir/aconfig.go new file mode 100644 index 0000000..01b3cf4 --- /dev/null +++ b/test/fixedbugs/issue59709.dir/aconfig.go @@ -0,0 +1,10 @@ +// Copyright 2023 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. + +package aconfig + +type Config struct { + name string + blah int +} diff --git a/test/fixedbugs/issue59709.dir/bresource.go b/test/fixedbugs/issue59709.dir/bresource.go new file mode 100644 index 0000000..9fae099 --- /dev/null +++ b/test/fixedbugs/issue59709.dir/bresource.go @@ -0,0 +1,27 @@ +// Copyright 2023 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. + +package bresource + +type Resource[T any] struct { + name string + initializer Initializer[T] + cfg ResConfig + value T +} + +func Should[T any](r *Resource[T], e error) bool { + return r.cfg.ShouldRetry(e) +} + +type ResConfig struct { + ShouldRetry func(error) bool + TearDown func() +} + +type Initializer[T any] func(*int) (T, error) + +func New[T any](name string, f Initializer[T], cfg ResConfig) *Resource[T] { + return &Resource[T]{name: name, initializer: f, cfg: cfg} +} diff --git a/test/fixedbugs/issue59709.dir/cmem.go b/test/fixedbugs/issue59709.dir/cmem.go new file mode 100644 index 0000000..43c4fe9 --- /dev/null +++ b/test/fixedbugs/issue59709.dir/cmem.go @@ -0,0 +1,37 @@ +// Copyright 2023 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. + +package cmem + +import ( + "./aconfig" + "./bresource" +) + +type MemT *int + +var G int + +type memResource struct { + x *int +} + +func (m *memResource) initialize(*int) (res *int, err error) { + return nil, nil +} + +func (m *memResource) teardown() { +} + +func NewResource(cfg *aconfig.Config) *bresource.Resource[*int] { + res := &memResource{ + x: &G, + } + + return bresource.New("Mem", res.initialize, bresource.ResConfig{ + // We always would want to retry the Memcache initialization. + ShouldRetry: func(error) bool { return true }, + TearDown: res.teardown, + }) +} diff --git a/test/fixedbugs/issue59709.dir/dcache.go b/test/fixedbugs/issue59709.dir/dcache.go new file mode 100644 index 0000000..ea63219 --- /dev/null +++ b/test/fixedbugs/issue59709.dir/dcache.go @@ -0,0 +1,39 @@ +// Copyright 2023 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. + +package dcache + +import ( + "./aconfig" + "./bresource" + "./cmem" +) + +type Module struct { + cfg *aconfig.Config + err error + last any +} + +//go:noinline +func TD() { +} + +func (m *Module) Configure(x string) error { + if m.err != nil { + return m.err + } + res := cmem.NewResource(m.cfg) + m.last = res + + return nil +} + +func (m *Module) Blurb(x string, e error) bool { + res, ok := m.last.(*bresource.Resource[*int]) + if !ok { + panic("bad") + } + return bresource.Should(res, e) +} diff --git a/test/fixedbugs/issue59709.dir/main.go b/test/fixedbugs/issue59709.dir/main.go new file mode 100644 index 0000000..c699a01 --- /dev/null +++ b/test/fixedbugs/issue59709.dir/main.go @@ -0,0 +1,17 @@ +// Copyright 2023 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. + +package main + +import ( + "./dcache" +) + +func main() { + var m dcache.Module + m.Configure("x") + m.Configure("y") + var e error + m.Blurb("x", e) +} |