Skip to content

Commit f37b0c6

Browse files
committed
[dev.typeparams] cmd/compile/internal/types2: type alias decl requires go1.9
Add respective check to type checker. Remove respective check from the compiler's new type2-based noder. Updates #31793. Change-Id: I907e3acab4c136027a8c3db1e9bac301d209c2e1 Reviewed-on: https://go-review.googlesource.com/c/go/+/289570 Trust: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 7214884 commit f37b0c6

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/cmd/compile/internal/noder/decl.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) {
102102

103103
func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
104104
if decl.Alias {
105-
if !types.AllowsGoVersion(types.LocalPkg, 1, 9) {
106-
base.ErrorfAt(g.pos(decl), "type aliases only supported as of -lang=go1.9")
107-
}
108-
109105
name, _ := g.def(decl.Name)
110106
g.pragmaFlags(decl.Pragma, 0)
111107

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named
629629

630630
if alias {
631631
// type alias declaration
632+
if !check.allowVersion(obj.pkg, 1, 9) {
633+
check.errorf(tdecl, "type aliases requires go1.9 or later")
634+
}
632635

633636
obj.typ = Typ[Invalid]
634637
obj.typ = check.anyType(tdecl.Type)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Check Go language version-specific errors.
6+
7+
package go1_8 // go1.8
8+
9+
// type alias declarations
10+
type any /* ERROR type aliases requires go1.9 or later */ = interface{}

0 commit comments

Comments
 (0)