return // error already reported
}
- // compute result signature: instantiate if needed
- rsig = sig
+ // update result signature: instantiate if needed
if n > 0 {
rsig = check.instantiateSignature(call.Pos(), call.Fun, sig, targs[:n], xlist)
- }
-
- // Optimization: Only if the callee's parameter list was adjusted do we need to
- // compute it from the adjusted list; otherwise we can simply use the result
- // signature's parameter list. We only need the n type parameters and arguments
- // of the callee.
- if n > 0 && adjusted {
- sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(tparams[:n], targs[:n]), nil, check.context()).(*Tuple)
- } else {
- sigParams = rsig.params
+ // If the callee's parameter list was adjusted we need to update (instantiate)
+ // it separately. Otherwise we can simply use the result signature's parameter
+ // list.
+ if adjusted {
+ sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(tparams[:n], targs[:n]), nil, check.context()).(*Tuple)
+ } else {
+ sigParams = rsig.params
+ }
}
// compute argument signatures: instantiate if needed
*boolFieldAddr(cfg, "go115UsesCgo") = true
})
}
+
+func TestIssue61931(t *testing.T) {
+ const src = `
+package p
+
+func A(func(any), ...any) {}
+func B[T any](T) {}
+
+func _() {
+ A(B, nil // syntax error: missing ',' before newline in argument list
+}
+`
+ f, err := syntax.Parse(syntax.NewFileBase(pkgName(src)), strings.NewReader(src), func(error) {}, nil, 0)
+ if err == nil {
+ t.Fatal("expected syntax error")
+ }
+
+ var conf Config
+ conf.Check(f.PkgName.Value, []*syntax.File{f}, nil) // must not panic
+}
return // error already reported
}
- // compute result signature: instantiate if needed
- rsig = sig
+ // update result signature: instantiate if needed
if n > 0 {
rsig = check.instantiateSignature(call.Pos(), call.Fun, sig, targs[:n], xlist)
- }
-
- // Optimization: Only if the callee's parameter list was adjusted do we need to
- // compute it from the adjusted list; otherwise we can simply use the result
- // signature's parameter list. We only need the n type parameters and arguments
- // of the callee.
- if n > 0 && adjusted {
- sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(tparams[:n], targs[:n]), nil, check.context()).(*Tuple)
- } else {
- sigParams = rsig.params
+ // If the callee's parameter list was adjusted we need to update (instantiate)
+ // it separately. Otherwise we can simply use the result signature's parameter
+ // list.
+ if adjusted {
+ sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(tparams[:n], targs[:n]), nil, check.context()).(*Tuple)
+ } else {
+ sigParams = rsig.params
+ }
}
// compute argument signatures: instantiate if needed
"fmt"
"go/ast"
"go/importer"
+ "go/parser"
"go/token"
"internal/testenv"
"regexp"
*boolFieldAddr(cfg, "go115UsesCgo") = true
})
}
+
+func TestIssue61931(t *testing.T) {
+ const src = `
+package p
+
+func A(func(any), ...any) {}
+func B[T any](T) {}
+
+func _() {
+ A(B, nil // syntax error: missing ',' before newline in argument list
+}
+`
+ fset := token.NewFileSet()
+ f, err := parser.ParseFile(fset, pkgName(src), src, 0)
+ if err == nil {
+ t.Fatal("expected syntax error")
+ }
+
+ var conf Config
+ conf.Check(f.Name.Name, fset, []*ast.File{f}, nil) // must not panic
+}