// Skip any generic functions
continue
}
+ // transformCall() below depends on CurFunc being set.
+ ir.CurFunc = decl.(*ir.Func)
case ir.OAS, ir.OAS2, ir.OAS2DOTTYPE, ir.OAS2FUNC, ir.OAS2MAPR, ir.OAS2RECV, ir.OASOP:
// These are all the various kinds of global assignments,
if base.Flag.W > 1 && modified {
ir.Dump(fmt.Sprintf("\nmodified %v", decl), decl)
}
+ ir.CurFunc = nil
// We may have seen new fully-instantiated generic types while
// instantiating any needed functions/methods in the above
// function. If so, instantiate all the methods of those types
newf.Nname.Func = newf
newf.Nname.Defn = newf
newsym.Def = newf.Nname
+ savef := ir.CurFunc
+ // transformCall/transformReturn (called during stenciling of the body)
+ // depend on ir.CurFunc being set.
ir.CurFunc = newf
assert(len(tparams) == len(targs))
// Make sure name/type of newf is set before substituting the body.
newf.Body = subst.list(gf.Body)
- ir.CurFunc = nil
+ ir.CurFunc = savef
return newf
}
--- /dev/null
+// run -gcflags=-G=3
+
+// Copyright 2021 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 (
+ "fmt"
+ "log"
+)
+
+func try[T any](v T, err error) T {
+ if err != nil {
+ panic(err)
+ }
+ return v
+}
+
+func handle(handle func(error)) {
+ if issue := recover(); issue != nil {
+ if e, ok := issue.(error); ok && e != nil {
+ handle(e)
+ } else {
+ handle(fmt.Errorf("%v", e))
+ }
+ }
+}
+
+func main() {
+ defer handle(func(e error) { log.Fatalln(e) })
+ _ = try(fmt.Print(""))
+}