From f37b0c6c12072edef19569c7f0b456ab7e570385 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 3 Feb 2021 22:34:34 -0800 Subject: [PATCH] [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 Reviewed-by: Robert Findley --- src/cmd/compile/internal/noder/decl.go | 4 ---- src/cmd/compile/internal/types2/decl.go | 3 +++ src/cmd/compile/internal/types2/testdata/go1_8.src | 10 ++++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/cmd/compile/internal/types2/testdata/go1_8.src diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go index 9862f452fdcfe7..a1596be4a424ab 100644 --- a/src/cmd/compile/internal/noder/decl.go +++ b/src/cmd/compile/internal/noder/decl.go @@ -102,10 +102,6 @@ func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) { func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) { if decl.Alias { - if !types.AllowsGoVersion(types.LocalPkg, 1, 9) { - base.ErrorfAt(g.pos(decl), "type aliases only supported as of -lang=go1.9") - } - name, _ := g.def(decl.Name) g.pragmaFlags(decl.Pragma, 0) diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go index 0b7956f28783cb..59d0a112b1264b 100644 --- a/src/cmd/compile/internal/types2/decl.go +++ b/src/cmd/compile/internal/types2/decl.go @@ -629,6 +629,9 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named if alias { // type alias declaration + if !check.allowVersion(obj.pkg, 1, 9) { + check.errorf(tdecl, "type aliases requires go1.9 or later") + } obj.typ = Typ[Invalid] obj.typ = check.anyType(tdecl.Type) diff --git a/src/cmd/compile/internal/types2/testdata/go1_8.src b/src/cmd/compile/internal/types2/testdata/go1_8.src new file mode 100644 index 00000000000000..0f3ba9443bd531 --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/go1_8.src @@ -0,0 +1,10 @@ +// 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. + +// Check Go language version-specific errors. + +package go1_8 // go1.8 + +// type alias declarations +type any /* ERROR type aliases requires go1.9 or later */ = interface{}