// If successful, infer returns the complete list of given and inferred type arguments, one for each
// type parameter. Otherwise the result is nil and appropriate errors will be reported.
func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type, params *Tuple, args []*operand) (inferred []Type) {
- if debug {
+ // Don't verify result conditions if there's no error handler installed:
+ // in that case, an error leads to an exit panic and the result value may
+ // be incorrect. But in that case it doesn't matter because callers won't
+ // be able to use it either.
+ if check.conf.Error != nil {
defer func() {
assert(inferred == nil || len(inferred) == len(tparams) && !containsNil(inferred))
}()
var conf Config
conf.Check(f.PkgName.Value, []*syntax.File{f}, nil) // must not panic
}
+
+func TestIssue61938(t *testing.T) {
+ const src = `
+package p
+
+func f[T any]() {}
+func _() { f() }
+`
+ // no error handler provided (this issue)
+ var conf Config
+ typecheck(src, &conf, nil) // must not panic
+
+ // with error handler (sanity check)
+ conf.Error = func(error) {}
+ typecheck(src, &conf, nil) // must not panic
+}
// If successful, infer returns the complete list of given and inferred type arguments, one for each
// type parameter. Otherwise the result is nil and appropriate errors will be reported.
func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type, params *Tuple, args []*operand) (inferred []Type) {
- if debug {
+ // Don't verify result conditions if there's no error handler installed:
+ // in that case, an error leads to an exit panic and the result value may
+ // be incorrect. But in that case it doesn't matter because callers won't
+ // be able to use it either.
+ if check.conf.Error != nil {
defer func() {
assert(inferred == nil || len(inferred) == len(tparams) && !containsNil(inferred))
}()
var conf Config
conf.Check(f.Name.Name, fset, []*ast.File{f}, nil) // must not panic
}
+
+func TestIssue61938(t *testing.T) {
+ const src = `
+package p
+
+func f[T any]() {}
+func _() { f() }
+`
+ // no error handler provided (this issue)
+ var conf Config
+ typecheck(src, &conf, nil) // must not panic
+
+ // with error handler (sanity check)
+ conf.Error = func(error) {}
+ typecheck(src, &conf, nil) // must not panic
+}