Skip to content

Commit ad95e7f

Browse files
committed
gotypes: add a link to the 1.18 API guide, and fix links
Update the go/types guide to have a link to the new 1.18 API guide, for now. Also fix some links to pkg.go.dev and golang.org/x that were amended in the autogenerated README.md rather than the original source. For golang/go#50676 Change-Id: Ib98ed095d74be02046c426e51f1ae2b9ceb03b0d Reviewed-on: https://go-review.googlesource.com/c/example/+/389656 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 787a929 commit ad95e7f

File tree

8 files changed

+40
-25
lines changed

8 files changed

+40
-25
lines changed

gotypes/README.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This document is maintained by Alan Donovan `[email protected]`.
99

1010
# Contents
1111

12+
1. [Changes in Go 1.18](#changes-in-go-1.18)
1213
1. [Introduction](#introduction)
1314
1. [An Example](#an-example)
1415
1. [Objects](#objects)
@@ -33,6 +34,13 @@ This document is maintained by Alan Donovan `[email protected]`.
3334
1. [Formatting support](#formatting-support)
3435
1. [Getting from A to B](#getting-from-a-to-b)
3536

37+
# Changes in Go 1.18
38+
39+
Go 1.18 introduces generic Go code, and several corresponding new APIs for
40+
`go/types`. This document is not yet up-to-date for these changes, but a guide
41+
to the new changes exists at
42+
[`x/exp/typeparams/example`](https://github.com/golang/exp/tree/master/typeparams/example).
43+
3644
# Introduction
3745

3846

@@ -995,7 +1003,7 @@ Use this function instead:
9951003

9961004

9971005
For the same reason, you should not use a `Type` as a key in a map.
998-
The [`golang.org/x/tools/go/types/typeutil` package](https://godoc.org/golang.org/x/tools/go/types/typeutil)
1006+
The [`golang.org/x/tools/go/types/typeutil` package](https://pkg.go.dev/golang.org/x/tools/go/types/typeutil)
9991007
provides a map keyed by types that uses the correct
10001008
equivalence relation.
10011009

@@ -2225,7 +2233,7 @@ function.
22252233

22262234
Here's a typical invocation on the standard `encoding/xml` package.
22272235
It reports a number of places where the 7-word
2228-
[`StartElement` type](https://godoc.org/encoding/xml#StartElement)
2236+
[`StartElement` type](https://pkg.go.dev/encoding/xml#StartElement)
22292237
is copied.
22302238

22312239

@@ -2288,7 +2296,7 @@ ran a `go install` or `go build -i` command.
22882296

22892297

22902298

2291-
The [`golang.org/tools/x/go/loader` package](https://godoc.org/golang.org/x/tools/go/loader)
2299+
The [`golang.org/tools/x/go/loader` package](https://pkg.go.dev/golang.org/x/tools/go/loader)
22922300
provides an alternative `Importer` that addresses
22932301
some of these problems.
22942302
It loads a complete program from source, performing
@@ -2524,13 +2532,13 @@ of the form "I have an A; I need the corresponding B".
25242532

25252533
To map **from a `token.Pos` to an `ast.Node`**, call the
25262534
helper function
2527-
[`astutil.PathEnclosingInterval`](https://godoc.org/golang.org/x/tools/go/ast/astutil#PathEnclosingInterval).
2535+
[`astutil.PathEnclosingInterval`](https://pkg.go.dev/golang.org/x/tools/go/ast/astutil#PathEnclosingInterval).
25282536
It returns the enclosing `ast.Node`, and all its ancestors up to
25292537
the root of the file.
25302538
You must know which file `*ast.File` the `token.Pos` belongs to.
25312539
Alternatively, you can search an entire program loaded by the
25322540
`loader` package, using
2533-
[`(*loader.Program).PathEnclosingInterval`](https://godoc.org/golang.org/x/tools/go/loader#Program.PathEnclosingInterval).
2541+
[`(*loader.Program).PathEnclosingInterval`](https://pkg.go.dev/golang.org/x/tools/go/loader#Program.PathEnclosingInterval).
25342542

25352543

25362544

gotypes/defsuses/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858

5959
/*
6060
//!+output
61-
$ go build github.com/golang/example/gotypes/defsuses
61+
$ go build golang.org/x/example/gotypes/defsuses
6262
$ ./defsuses
6363
hello.go:1:9: "main" defines <nil>
6464
hello.go:5:6: "main" defines func hello.main()

gotypes/go-types.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ This document is maintained by Alan Donovan `[email protected]`.
1010

1111
%toc
1212

13+
# Changes in Go 1.18
14+
15+
Go 1.18 introduces generics, and several corresponding new APIs for `go/types`.
16+
This document is not yet up-to-date for these changes, but a guide to the new
17+
changes exists at
18+
[`x/exp/typeparams/example`](https://github.com/golang/exp/tree/master/typeparams/example).
19+
1320
# Introduction
1421

1522

@@ -55,7 +62,7 @@ constant expressions, as we'll see in
5562

5663

5764

58-
The [`golang.org/x/tools/go/loader` package](https://godoc.org/golang.org/x/tools/go/loader)
65+
The [`golang.org/x/tools/go/loader` package](https://pkg.go.dev/golang.org/x/tools/go/loader)
5966
from the `x/tools` repository is a client of the type
6067
checker that loads, parses, and type-checks a complete Go program from
6168
source code.
@@ -110,7 +117,7 @@ the _hello, world_ program, supplied as a string.
110117
Later examples will be variations on this one, and we'll often omit
111118
boilerplate details such as parsing.
112119
To check out and build the examples,
113-
run `go get github.com/golang/example/gotypes/...`.
120+
run `go get golang.org/x/example/gotypes/...`.
114121

115122

116123
%include pkginfo/main.go
@@ -142,7 +149,7 @@ how to locate the imported packages.
142149
Here we use `importer.Default()`, which loads compiler-generated
143150
export data, but we'll explore alternatives in [Imports](#imports).
144151

145-
152+
146153

147154
Fourth, the program calls `Check`.
148155
This creates a `Package` whose path is `"cmd/hello"`, and
@@ -602,7 +609,7 @@ by calling its `(*Func).Scope` method.
602609

603610

604611
<!--
605-
TODO: explain explicit and implicit blocks
612+
TODO: explain explicit and implicit blocks
606613
TODO: explain Dot imports.
607614
TODO: explain that Func blocks are associated with FuncType (not FuncDecl or FuncLit)
608615
-->
@@ -668,7 +675,7 @@ does a name lookup at a specific position in that lexical block.
668675

669676

670677

671-
A typical input is shown below.
678+
A typical input is shown below.
672679
The first comment causes a lookup of `"append"` in the file block.
673680
The second comment looks up `"fmt"` in the `main` function's block,
674681
and so on.
@@ -814,7 +821,7 @@ Use this function instead:
814821

815822

816823
For the same reason, you should not use a `Type` as a key in a map.
817-
The [`golang.org/x/tools/go/types/typeutil` package](https://godoc.org/golang.org/x/tools/go/types/typeutil)
824+
The [`golang.org/x/tools/go/types/typeutil` package](https://pkg.go.dev/golang.org/x/tools/go/types/typeutil)
818825
provides a map keyed by types that uses the correct
819826
equivalence relation.
820827

@@ -996,7 +1003,7 @@ The type checker builds the exact same data structures given this input:
9961003

9971004
A similar issue applies to the methods of named interface types.
9981005

999-
1006+
10001007
## Tuple Types
10011008

10021009

@@ -1230,7 +1237,7 @@ interface `v`, then the type assertion is not legal, as in this example:
12301237

12311238

12321239
// error: io.Writer is not assertible to int
1233-
func f(w io.Writer) int { return w.(int) }
1240+
func f(w io.Writer) int { return w.(int) }
12341241

12351242

12361243

@@ -1443,7 +1450,7 @@ all.)
14431450

14441451

14451452
The final two parameters of `LookupFieldOrMethod` are `(pkg
1446-
*Package, name string)`.
1453+
*Package, name string)`.
14471454
Together they specify the name of the field or method to look up.
14481455
This brings us to `Id`s.
14491456

@@ -1654,7 +1661,7 @@ Constants are represented using the `Value` interface from the
16541661
package constant // go/constant
16551662

16561663
type Value interface {
1657-
Kind() Kind
1664+
Kind() Kind
16581665
}
16591666

16601667
type Kind int // one of Unknown, Bool, String, Int, Float, Complex
@@ -1787,7 +1794,7 @@ function.
17871794

17881795
Here's a typical invocation on the standard `encoding/xml` package.
17891796
It reports a number of places where the 7-word
1790-
[`StartElement` type](https://godoc.org/encoding/xml#StartElement)
1797+
[`StartElement` type](https://pkg.go.dev/encoding/xml#StartElement)
17911798
is copied.
17921799

17931800

@@ -1843,7 +1850,7 @@ ran a `go install` or `go build -i` command.
18431850

18441851

18451852

1846-
The [`golang.org/tools/x/go/loader` package](https://godoc.org/golang.org/x/tools/go/loader)
1853+
The [`golang.org/tools/x/go/loader` package](https://pkg.go.dev/golang.org/x/tools/go/loader)
18471854
provides an alternative `Importer` that addresses
18481855
some of these problems.
18491856
It loads a complete program from source, performing
@@ -2025,13 +2032,13 @@ of the form "I have an A; I need the corresponding B".
20252032

20262033
To map **from a `token.Pos` to an `ast.Node`**, call the
20272034
helper function
2028-
[`astutil.PathEnclosingInterval`](https://godoc.org/golang.org/x/tools/go/ast/astutil#PathEnclosingInterval).
2035+
[`astutil.PathEnclosingInterval`](https://pkg.go.dev/golang.org/x/tools/go/ast/astutil#PathEnclosingInterval).
20292036
It returns the enclosing `ast.Node`, and all its ancestors up to
20302037
the root of the file.
20312038
You must know which file `*ast.File` the `token.Pos` belongs to.
20322039
Alternatively, you can search an entire program loaded by the
20332040
`loader` package, using
2034-
[`(*loader.Program).PathEnclosingInterval`](https://godoc.org/golang.org/x/tools/go/loader#Program.PathEnclosingInterval).
2041+
[`(*loader.Program).PathEnclosingInterval`](https://pkg.go.dev/golang.org/x/tools/go/loader#Program.PathEnclosingInterval).
20352042

20362043

20372044

gotypes/implements/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func main() {
6868

6969
/*
7070
//!+output
71-
$ go build github.com/golang/example/gotypes/implements
71+
$ go build golang.org/x/example/gotypes/implements
7272
$ ./implements
7373
*hello.A satisfies hello.I
7474
hello.B satisfies hello.I

gotypes/lookup/lookup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func main() {
6565

6666
/*
6767
//!+output
68-
$ go build github.com/golang/example/gotypes/lookup
68+
$ go build golang.org/x/example/gotypes/lookup
6969
$ ./lookup
7070
At hello.go:6:1, "append" = builtin append
7171
At hello.go:8:9, "fmt" = package fmt

gotypes/nilfunc/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func CheckNilFuncComparison(info *types.Info, n ast.Node) {
9595

9696
/*
9797
//!+output
98-
$ go build github.com/golang/example/gotypes/nilfunc
98+
$ go build golang.org/x/example/gotypes/nilfunc
9999
$ ./nilfunc
100100
input.go:7:5: comparison of function Bytes == nil is always false
101101
input.go:7:25: comparison of function Repeat != nil is always true

gotypes/pkginfo/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func main() {
5252

5353
/*
5454
//!+output
55-
$ go build github.com/golang/example/gotypes/pkginfo
55+
$ go build golang.org/x/example/gotypes/pkginfo
5656
$ ./pkginfo
5757
Package "cmd/hello"
5858
Name: main

gotypes/typeandvalue/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func mode(tv types.TypeAndValue) string {
9696

9797
/*
9898
//!+output
99-
$ go build github.com/golang/example/gotypes/typeandvalue
99+
$ go build golang.org/x/example/gotypes/typeandvalue
100100
$ ./typeandvalue
101101
make(map[string]int) mode: value
102102
type: map[string]int

0 commit comments

Comments
 (0)