Skip to content

Commit

Permalink
[dev.typeparams] cmd/compile/internal/types2: type alias decl require…
Browse files Browse the repository at this point in the history
…s 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 <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
griesemer committed Feb 4, 2021
1 parent 7214884 commit f37b0c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/cmd/compile/internal/noder/decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/types2/decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/cmd/compile/internal/types2/testdata/go1_8.src
Original file line number Diff line number Diff line change
@@ -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{}

0 comments on commit f37b0c6

Please sign in to comment.