}
base.ErrorfAt(m.makeXPos(terr.Pos), terr.Code, "%s", msg)
},
- Importer: &importer,
- Sizes: &gcSizes{},
- EnableReverseTypeInference: true,
+ Importer: &importer,
+ Sizes: &gcSizes{},
}
info := &types2.Info{
StoreTypesInSyntax: true,
// If DisableUnusedImportCheck is set, packages are not checked
// for unused imports.
DisableUnusedImportCheck bool
-
- // If EnableReverseTypeInference is set, uninstantiated and
- // partially instantiated generic functions may be assigned
- // (incl. returned) to variables of function type and type
- // inference will attempt to infer the missing type arguments.
- // See proposal go.dev/issue/59338.
- EnableReverseTypeInference bool
}
func srcimporter_setUsesCgo(conf *Config) {
for _, test := range tests {
imports := make(testImporter)
- conf := Config{
- Importer: imports,
- EnableReverseTypeInference: true,
- }
+ conf := Config{Importer: imports}
instMap := make(map[*syntax.Name]Instance)
useMap := make(map[*syntax.Name]Object)
makePkg := func(src string) *Package {
// collect type parameters from generic function arguments
var genericArgs []int // indices of generic function arguments
- if check.conf.EnableReverseTypeInference {
+ if enableReverseTypeInference {
for i, arg := range args {
// generic arguments cannot have a defined (*Named) type - no need for underlying type below
if asig, _ := arg.typ.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
flags := flag.NewFlagSet("", flag.PanicOnError)
flags.StringVar(&conf.GoVersion, "lang", "", "")
flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
- flags.BoolVar(&conf.EnableReverseTypeInference, "reverseTypeInference", false, "")
if err := parseFlags(filenames[0], nil, flags); err != nil {
t.Fatal(err)
}
}
case *Signature:
if t.tparams != nil {
- if check.conf.EnableReverseTypeInference && T != nil {
+ if enableReverseTypeInference && T != nil {
if tsig, _ := under(T).(*Signature); tsig != nil {
check.funcInst(tsig, x.Pos(), x, nil)
return
case *syntax.IndexExpr:
if check.indexExpr(x, e) {
var tsig *Signature
- if check.conf.EnableReverseTypeInference && T != nil {
+ if enableReverseTypeInference && T != nil {
tsig, _ = under(T).(*Signature)
}
check.funcInst(tsig, e.Pos(), x, e)
"strings"
)
+// If enableReverseTypeInference is set, uninstantiated and
+// partially instantiated generic functions may be assigned
+// (incl. returned) to variables of function type and type
+// inference will attempt to infer the missing type arguments.
+// Available with go1.21.
+const enableReverseTypeInference = true // disable for debugging
+
// infer attempts to infer the complete set of type arguments for generic function instantiation/call
// based on the given type parameters tparams, type arguments targs, function parameters params, and
// function arguments args, if any. There must be at least one type parameter, no more type arguments
file, err := syntax.ParseFile(filename, nil, nil, 0)
if err == nil {
conf := Config{
- GoVersion: goVersion,
- Importer: stdLibImporter,
- EnableReverseTypeInference: true,
+ GoVersion: goVersion,
+ Importer: stdLibImporter,
}
_, err = conf.Check(filename, []*syntax.File{file}, nil)
}
// typecheck package files
conf := Config{
- Error: func(err error) { t.Error(err) },
- Importer: stdLibImporter,
- EnableReverseTypeInference: true,
+ Error: func(err error) { t.Error(err) },
+ Importer: stdLibImporter,
}
info := Info{Uses: make(map[*syntax.Name]Object)}
conf.Check(path, files, &info)
// If DisableUnusedImportCheck is set, packages are not checked
// for unused imports.
DisableUnusedImportCheck bool
-
- // If _EnableReverseTypeInference is set, uninstantiated and
- // partially instantiated generic functions may be assigned
- // (incl. returned) to variables of function type and type
- // inference will attempt to infer the missing type arguments.
- // See proposal go.dev/issue/59338.
- _EnableReverseTypeInference bool
}
func srcimporter_setUsesCgo(conf *Config) {
for _, test := range tests {
imports := make(testImporter)
- conf := Config{
- Importer: imports,
- // Unexported field: set below with boolFieldAddr
- // _EnableReverseTypeInference: true,
- }
- *boolFieldAddr(&conf, "_EnableReverseTypeInference") = true
+ conf := Config{Importer: imports}
instMap := make(map[*ast.Ident]Instance)
useMap := make(map[*ast.Ident]Object)
makePkg := func(src string) *Package {
// collect type parameters from generic function arguments
var genericArgs []int // indices of generic function arguments
- if check.conf._EnableReverseTypeInference {
+ if enableReverseTypeInference {
for i, arg := range args {
// generic arguments cannot have a defined (*Named) type - no need for underlying type below
if asig, _ := arg.typ.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
flags := flag.NewFlagSet("", flag.PanicOnError)
flags.StringVar(&conf.GoVersion, "lang", "", "")
flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
- flags.BoolVar(boolFieldAddr(&conf, "_EnableReverseTypeInference"), "reverseTypeInference", false, "")
if err := parseFlags(filenames[0], srcs[0], flags); err != nil {
t.Fatal(err)
}
}
case *Signature:
if t.tparams != nil {
- if check.conf._EnableReverseTypeInference && T != nil {
+ if enableReverseTypeInference && T != nil {
if tsig, _ := under(T).(*Signature); tsig != nil {
check.funcInst(tsig, x.Pos(), x, nil)
return
ix := typeparams.UnpackIndexExpr(e)
if check.indexExpr(x, ix) {
var tsig *Signature
- if check.conf._EnableReverseTypeInference && T != nil {
+ if enableReverseTypeInference && T != nil {
tsig, _ = under(T).(*Signature)
}
check.funcInst(tsig, e.Pos(), x, ix)
"strings"
)
+// If enableReverseTypeInference is set, uninstantiated and
+// partially instantiated generic functions may be assigned
+// (incl. returned) to variables of function type and type
+// inference will attempt to infer the missing type arguments.
+// Available with go1.21.
+const enableReverseTypeInference = true // disable for debugging
+
// infer attempts to infer the complete set of type arguments for generic function instantiation/call
// based on the given type parameters tparams, type arguments targs, function parameters params, and
// function arguments args, if any. There must be at least one type parameter, no more type arguments
GoVersion: goVersion,
Importer: stdLibImporter,
}
- *boolFieldAddr(&conf, "_EnableReverseTypeInference") = true
_, err = conf.Check(filename, fset, []*ast.File{file}, nil)
}
},
Importer: stdLibImporter,
}
- *boolFieldAddr(&conf, "_EnableReverseTypeInference") = true
info := Info{Uses: make(map[*ast.Ident]Object)}
conf.Check(path, fset, files, &info)
+// -lang=go1.20
+
// 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.
func f[P any](P) {}
// This must not crash.
-var _ func(int) = f // ERROR "cannot use generic function f without instantiation"
+var _ func(int) = f // ERROR "implicitly instantiated function in assignment requires go1.21 or later"
-// -reverseTypeInference
-
// 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.
-// -reverseTypeInference -lang=go1.20
+// -lang=go1.20
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
-// -reverseTypeInference
-
// 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.
-// -reverseTypeInference -lang=go1.17
+// -lang=go1.17
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
-// -reverseTypeInference
-
// 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.
-// -reverseTypeInference
-
// 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.