diff options
author | Robert Griesemer <gri@golang.org> | 2016-10-25 14:09:18 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2016-10-27 17:44:45 +0000 |
commit | 03d81b5ed91dfb3a2d1041bfe80dd94e7f06a3c4 (patch) | |
tree | e4cd0b9b39f921dbdfb2e3ff0827be48106d887a /test/alias3.dir | |
parent | 81038d2e2b588f9df45d20a2ca0be446b0e421b2 (diff) | |
download | go-03d81b5ed91dfb3a2d1041bfe80dd94e7f06a3c4.tar.gz go-03d81b5ed91dfb3a2d1041bfe80dd94e7f06a3c4.zip |
cmd/compile: import/export of alias declarations
This CL completes support for alias declarations in the compiler.
Also:
- increased export format version
- updated various comments
For #16339.
Fixes #17487.
Change-Id: Ic6945fc44c0041771eaf9dcfe973f601d14de069
Reviewed-on: https://go-review.googlesource.com/32090
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/alias3.dir')
-rw-r--r-- | test/alias3.dir/a.go | 54 | ||||
-rw-r--r-- | test/alias3.dir/b.go | 61 | ||||
-rw-r--r-- | test/alias3.dir/c.go | 66 |
3 files changed, 181 insertions, 0 deletions
diff --git a/test/alias3.dir/a.go b/test/alias3.dir/a.go new file mode 100644 index 0000000000..c14f834630 --- /dev/null +++ b/test/alias3.dir/a.go @@ -0,0 +1,54 @@ +// 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. + +package a + +import ( + "bytes" + "go/build" + "io" + "math" +) + +func F(c *build.Context, w io.Writer) {} + +func Inlined() bool { var w Writer; return w == nil } + +func Check() { + if Pi != math.Pi { + panic(0) + } + + var w Writer + F(new(Context), w) + F(new(build.Context), bytes.NewBuffer(nil)) + + if &Default != &build.Default { + panic(1) + } + + if Sin(1) != math.Sin(1) { + panic(2) + } + + var _ *LimitedReader = new(LimitedReader2) +} + +// export aliases +const Pi => math.Pi + +type ( + Context => build.Context // not an interface + Writer => io.Writer // interface +) + +// different aliases may refer to the same original +type LimitedReader => io.LimitedReader +type LimitedReader2 => io.LimitedReader + +var Default => build.Default +var Default2 => build.Default + +func Sin => math.Sin +func Sin2 => math.Sin diff --git a/test/alias3.dir/b.go b/test/alias3.dir/b.go new file mode 100644 index 0000000000..d4550feca5 --- /dev/null +++ b/test/alias3.dir/b.go @@ -0,0 +1,61 @@ +// 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. + +package b + +import ( + "./a" + "bytes" + "go/build" + "io" + "math" +) + +func F => a.F +func Inlined => a.Inlined + +var _ func(*Context, io.Writer) = a.F + +// check aliases +func Check() { + if Pi != math.Pi { + panic(0) + } + + var w Writer + a.F(new(Context), w) + F(new(build.Context), bytes.NewBuffer(nil)) + + if !Inlined() { + panic(1) + } + + if &Default != &build.Default { + panic(2) + } + + if Sin(1) != math.Sin(1) { + panic(3) + } + + var _ *LimitedReader = new(LimitedReader2) +} + +// re-export aliases +const Pi => a.Pi + +type ( + Context => a.Context // not an interface + Writer => a.Writer // interface +) + +// different aliases may refer to the same original +type LimitedReader => a.LimitedReader +type LimitedReader2 => a.LimitedReader2 + +var Default => a.Default +var Default2 => a.Default2 + +func Sin => a.Sin +func Sin2 => a.Sin diff --git a/test/alias3.dir/c.go b/test/alias3.dir/c.go new file mode 100644 index 0000000000..701483fac2 --- /dev/null +++ b/test/alias3.dir/c.go @@ -0,0 +1,66 @@ +// 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. + +package main + +import ( + "./a" + "./b" + "bytes" + "go/build" + "math" +) + +func f => b.F +func inlined => b.Inlined + +var _ func(*context, a.Writer) = f + +func Check() { + if pi != math.Pi { + panic(0) + } + + var w writer + b.F(new(context), w) + f(new(build.Context), bytes.NewBuffer(nil)) + + if !inlined() { + panic(1) + } + + if &default_ != &build.Default { + panic(2) + } + + if sin(1) != math.Sin(1) { + panic(3) + } + + var _ *limitedReader = new(limitedReader2) +} + +// local aliases +const pi => b.Pi + +type ( + context => b.Context // not an interface + writer => b.Writer // interface +) + +// different aliases may refer to the same original +type limitedReader => b.LimitedReader +type limitedReader2 => b.LimitedReader2 + +var default_ => b.Default +var default2 => b.Default2 + +func sin => b.Sin +func sin2 => b.Sin + +func main() { + a.Check() + b.Check() + Check() +} |