1
0
mirror of https://github.com/golang/go synced 2024-09-30 15:18:32 -06:00
go/test/alias2.go
Matthew Dempsky adda7ad295 cmd/compile/internal/gc: enable new parser by default
Change-Id: I3c784986755cfbbe1b8eb8da4d64227bd109a3b0
Reviewed-on: https://go-review.googlesource.com/27203
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-10-25 22:28:40 +00:00

97 lines
3.1 KiB
Go

// errorcheck
// Copyright 2016 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.
// Test basic restrictions on alias declarations.
package p
import (
"fmt" // use at most once (to test "imported but not used" error)
"go/build"
. "go/build"
"io"
"math"
"unsafe"
)
// helper
var before struct {
f
}
// aliases must refer to package-qualified identifiers
// TODO(gri) should only see one error for declaration below - fix this
const _ => 0 // ERROR "unexpected literal 0|_ is not a package-qualified identifier"
type _ => _ // ERROR "_ is not a package-qualified identifier"
type t => _ // ERROR "_ is not a package-qualified identifier"
const _ => iota // ERROR "iota is not a package-qualified identifier"
type _ => int // ERROR "int is not a package-qualified identifier"
const c => iota // ERROR "iota is not a package-qualified identifier"
type t => int // ERROR "int is not a package-qualified identifier"
// dot-imported identifiers are not qualified identifiers
// TODO(gri) fix error printing - should not print a qualified identifier...
var _ => Default // ERROR "build\.Default is not a package-qualified identifier"
// qualified identifiers must start with a package
var _ => before.f // ERROR "before is not a package"
func _ => before.f // ERROR "before is not a package"
var _ => after.m // ERROR "after is not a package"
func _ => after.m // ERROR "after is not a package"
var v => before.f // ERROR "before is not a package"
func f => before.f // ERROR "before is not a package"
var v => after.m // ERROR "after is not a package"
func f => after.m // ERROR "after is not a package"
// TODO(gri) fix error printing - should not print a qualified identifier...
var _ => Default.ARCH // ERROR "build.Default is not a package"
// aliases may not refer to package unsafe
type ptr => unsafe.Pointer // ERROR "ptr refers to package unsafe"
func size => unsafe.Sizeof // ERROR "size refers to package unsafe"
// aliases must refer to entities of the same kind
const _ => math.Pi
const pi => math.Pi
const pi1 => math.Sin // ERROR "math.Sin is not a constant"
type _ => io.Writer
type writer => io.Writer
type writer1 => math.Sin // ERROR "math.Sin is not a type"
var _ => build.Default
var def => build.Default
var def1 => build.Import // ERROR "build.Import is not a variable"
func _ => math.Sin
func sin => math.Sin
func sin1 => math.Pi // ERROR "math.Pi is not a function"
// alias reference to a package marks package as used
func _ => fmt.Println
// TODO(gri) aliased cannot be exported yet - fix this
const Pi => math.Pi // ERROR "cannot export alias Pi"
type Writer => io.Writer // ERROR "cannot export alias Writer"
var Def => build.Default // ERROR "cannot export alias Def"
func Sin => math.Sin // ERROR "cannot export alias Sin"
// type aliases denote identical types
type myPackage => build.Package
var pkg myPackage
var _ build.Package = pkg // valid assignment
var _ *build.Package = &pkg // valid assignment
// helper
type after struct{}
func (after) m() {}