Use varType instead of instantiatedOperand to check if the type of a method expressions is instantiated.
This removes the last usage of instantiatedOperand, so it can be deleted.
Fixes #48048
Change-Id: I2b219dafe2bba3603100bb8f25b8ff4e8ef53841
Reviewed-on: https://go-review.googlesource.com/c/go/+/345970
Trust: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
goto Error
}
- check.instantiatedOperand(x)
+ if x.mode == typexpr {
+ x.typ = check.varType(e.X)
+ }
obj, index, indirect = LookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel)
if obj == nil {
}
}
}
-
-// instantiatedOperand reports an error of x is an uninstantiated (generic) type and sets x.typ to Typ[Invalid].
-func (check *Checker) instantiatedOperand(x *operand) {
- if x.mode == typexpr && isGeneric(x.typ) {
- check.errorf(x, "cannot use generic type %s without instantiation", x.typ)
- x.typ = Typ[Invalid]
- }
-}
--- /dev/null
+// 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 p
+
+type T[P any] struct{}
+
+func (T[_]) A() {}
+
+var _ = (T[int]).A
+var _ = (*T[int]).A
+
+var _ = (T /* ERROR cannot use generic type */).A
+var _ = (*T /* ERROR cannot use generic type */).A
goto Error
}
- check.instantiatedOperand(x)
+ if x.mode == typexpr {
+ x.typ = check.varType(e.X)
+ }
obj, index, indirect = LookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel)
if obj == nil {
}
}
}
-
-// instantiatedOperand reports an error of x is an uninstantiated (generic) type and sets x.typ to Typ[Invalid].
-func (check *Checker) instantiatedOperand(x *operand) {
- if x.mode == typexpr && isGeneric(x.typ) {
- check.errorf(x, _Todo, "cannot use generic type %s without instantiation", x.typ)
- x.typ = Typ[Invalid]
- }
-}
--- /dev/null
+// 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 p
+
+type T[P any] struct{}
+
+func (T[_]) A() {}
+
+var _ = (T[int]).A
+var _ = (*T[int]).A
+
+var _ = (T /* ERROR cannot use generic type */).A
+var _ = (*T /* ERROR cannot use generic type */).A