Skip to content

Commit f5c193e

Browse files
committed
types2: omit redundant generic type instantiation error if type is invalid
Fixes: #74725
1 parent 90b7d7a commit f5c193e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/cmd/compile/internal/types2/typexpr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (check *Checker) validVarType(e syntax.Expr, typ Type) {
194194
func (check *Checker) definedType(e syntax.Expr, def *TypeName) Type {
195195
typ := check.typInternal(e, def)
196196
assert(isTyped(typ))
197-
if isGeneric(typ) {
197+
if isGeneric(typ) && isValid(typ) {
198198
check.errorf(e, WrongTypeArgCount, "cannot use generic type %s without instantiation", typ)
199199
typ = Typ[Invalid]
200200
}

test/fixedbugs/issue74725.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// errorcheck
2+
3+
package main
4+
5+
type a = b[int] // ERROR "invalid recursive type a\n.*a refers to b\n.*b refers to a"
6+
type b[_ any] = a

0 commit comments

Comments
 (0)