|
10 | 10 |
|
11 | 11 | %toc |
12 | 12 |
|
| 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 | + |
13 | 20 | # Introduction |
14 | 21 |
|
15 | 22 |
|
@@ -55,7 +62,7 @@ constant expressions, as we'll see in |
55 | 62 |
|
56 | 63 |
|
57 | 64 |
|
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) |
59 | 66 | from the `x/tools` repository is a client of the type |
60 | 67 | checker that loads, parses, and type-checks a complete Go program from |
61 | 68 | source code. |
@@ -110,7 +117,7 @@ the _hello, world_ program, supplied as a string. |
110 | 117 | Later examples will be variations on this one, and we'll often omit |
111 | 118 | boilerplate details such as parsing. |
112 | 119 | 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/...`. |
114 | 121 |
|
115 | 122 |
|
116 | 123 | %include pkginfo/main.go |
@@ -142,7 +149,7 @@ how to locate the imported packages. |
142 | 149 | Here we use `importer.Default()`, which loads compiler-generated |
143 | 150 | export data, but we'll explore alternatives in [Imports](#imports). |
144 | 151 |
|
145 | | - |
| 152 | + |
146 | 153 |
|
147 | 154 | Fourth, the program calls `Check`. |
148 | 155 | This creates a `Package` whose path is `"cmd/hello"`, and |
@@ -602,7 +609,7 @@ by calling its `(*Func).Scope` method. |
602 | 609 |
|
603 | 610 |
|
604 | 611 | <!-- |
605 | | -TODO: explain explicit and implicit blocks |
| 612 | +TODO: explain explicit and implicit blocks |
606 | 613 | TODO: explain Dot imports. |
607 | 614 | TODO: explain that Func blocks are associated with FuncType (not FuncDecl or FuncLit) |
608 | 615 | --> |
@@ -668,7 +675,7 @@ does a name lookup at a specific position in that lexical block. |
668 | 675 |
|
669 | 676 |
|
670 | 677 |
|
671 | | -A typical input is shown below. |
| 678 | +A typical input is shown below. |
672 | 679 | The first comment causes a lookup of `"append"` in the file block. |
673 | 680 | The second comment looks up `"fmt"` in the `main` function's block, |
674 | 681 | and so on. |
@@ -814,7 +821,7 @@ Use this function instead: |
814 | 821 |
|
815 | 822 |
|
816 | 823 | 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) |
818 | 825 | provides a map keyed by types that uses the correct |
819 | 826 | equivalence relation. |
820 | 827 |
|
@@ -996,7 +1003,7 @@ The type checker builds the exact same data structures given this input: |
996 | 1003 |
|
997 | 1004 | A similar issue applies to the methods of named interface types. |
998 | 1005 |
|
999 | | - |
| 1006 | + |
1000 | 1007 | ## Tuple Types |
1001 | 1008 |
|
1002 | 1009 |
|
@@ -1230,7 +1237,7 @@ interface `v`, then the type assertion is not legal, as in this example: |
1230 | 1237 |
|
1231 | 1238 |
|
1232 | 1239 | // 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) } |
1234 | 1241 |
|
1235 | 1242 |
|
1236 | 1243 |
|
@@ -1443,7 +1450,7 @@ all.) |
1443 | 1450 |
|
1444 | 1451 |
|
1445 | 1452 | The final two parameters of `LookupFieldOrMethod` are `(pkg |
1446 | | -*Package, name string)`. |
| 1453 | +*Package, name string)`. |
1447 | 1454 | Together they specify the name of the field or method to look up. |
1448 | 1455 | This brings us to `Id`s. |
1449 | 1456 |
|
@@ -1654,7 +1661,7 @@ Constants are represented using the `Value` interface from the |
1654 | 1661 | package constant // go/constant |
1655 | 1662 |
|
1656 | 1663 | type Value interface { |
1657 | | - Kind() Kind |
| 1664 | + Kind() Kind |
1658 | 1665 | } |
1659 | 1666 |
|
1660 | 1667 | type Kind int // one of Unknown, Bool, String, Int, Float, Complex |
@@ -1787,7 +1794,7 @@ function. |
1787 | 1794 |
|
1788 | 1795 | Here's a typical invocation on the standard `encoding/xml` package. |
1789 | 1796 | 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) |
1791 | 1798 | is copied. |
1792 | 1799 |
|
1793 | 1800 |
|
@@ -1843,7 +1850,7 @@ ran a `go install` or `go build -i` command. |
1843 | 1850 |
|
1844 | 1851 |
|
1845 | 1852 |
|
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) |
1847 | 1854 | provides an alternative `Importer` that addresses |
1848 | 1855 | some of these problems. |
1849 | 1856 | It loads a complete program from source, performing |
@@ -2025,13 +2032,13 @@ of the form "I have an A; I need the corresponding B". |
2025 | 2032 |
|
2026 | 2033 | To map **from a `token.Pos` to an `ast.Node`**, call the |
2027 | 2034 | 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). |
2029 | 2036 | It returns the enclosing `ast.Node`, and all its ancestors up to |
2030 | 2037 | the root of the file. |
2031 | 2038 | You must know which file `*ast.File` the `token.Pos` belongs to. |
2032 | 2039 | Alternatively, you can search an entire program loaded by the |
2033 | 2040 | `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). |
2035 | 2042 |
|
2036 | 2043 |
|
2037 | 2044 |
|
|
0 commit comments