Skip to content

Commit 13c4909

Browse files
griesemergopherbot
authored andcommitted
go/types, types2: report error when using uninstantiated signature alias
For #67547. Fixes #67683. Change-Id: I9487820ab4e2bd257d253a7016df45729b29f836 Reviewed-on: https://go-review.googlesource.com/c/go/+/588855 Auto-Submit: Robert Griesemer <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent ee29dbe commit 13c4909

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
10131013
}
10141014
var what string
10151015
switch t := x.typ.(type) {
1016-
case *Named:
1016+
case *Alias, *Named:
10171017
if isGeneric(t) {
10181018
what = "type"
10191019
}

src/go/types/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ func (check *Checker) nonGeneric(T *target, x *operand) {
998998
}
999999
var what string
10001000
switch t := x.typ.(type) {
1001-
case *Named:
1001+
case *Alias, *Named:
10021002
if isGeneric(t) {
10031003
what = "type"
10041004
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// -goexperiment=aliastypeparams -gotypesalias=1
2+
3+
// Copyright 2024 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package p
8+
9+
type A[P any] func()
10+
11+
// alias signature types
12+
type B[P any] = func()
13+
type C[P any] = B[P]
14+
15+
var _ = A /* ERROR "cannot use generic type A without instantiation" */ (nil)
16+
17+
// generic alias signature types must be instantiated before use
18+
var _ = B /* ERROR "cannot use generic type B without instantiation" */ (nil)
19+
var _ = C /* ERROR "cannot use generic type C without instantiation" */ (nil)

0 commit comments

Comments
 (0)