Skip to content

Commit 015f894

Browse files
authored
Merge pull request #485 from xushiwei/q
TyAny
2 parents 250e083 + 3fae385 commit 015f894

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

ast.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,8 @@ func toMapType(pkg *Package, t *types.Map) ast.Expr {
234234
return &ast.MapType{Key: toType(pkg, t.Key()), Value: toType(pkg, t.Elem())}
235235
}
236236

237-
var (
238-
universeAny = types.Universe.Lookup("any")
239-
)
240-
241237
func toInterface(pkg *Package, t *types.Interface) ast.Expr {
242-
if t == universeAny.Type() {
238+
if t == TyAny {
243239
return ast.NewIdent("any")
244240
} else if interfaceIsImplicit(t) && t.NumEmbeddeds() == 1 {
245241
return toType(pkg, t.EmbeddedType(0))
@@ -355,7 +351,7 @@ func toExpr(pkg *Package, val interface{}, src ast.Node) *internal.Elem {
355351
}
356352

357353
var (
358-
iotaObj = types.Universe.Lookup("iota")
354+
iotaObj types.Object
359355
)
360356

361357
func toBasicKind(tok token.Token) types.BasicKind {

internal/go/format/format.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const parserMode = parser.ParseComments
5151
//
5252
// The function may return early (before the entire result is written)
5353
// and return a formatting error, for instance due to an incorrect AST.
54-
//
5554
func Node(dst io.Writer, fset *token.FileSet, node interface{}) error {
5655
// Determine if we have a complete source file (file != nil).
5756
var file *ast.File
@@ -100,7 +99,6 @@ func Node(dst io.Writer, fset *token.FileSet, node interface{}) error {
10099
// is applied to the result (such that it has the same leading and trailing
101100
// space as src), and the result is indented by the same amount as the first
102101
// line of src containing code. Imports are not sorted for partial source files.
103-
//
104102
func Source(src []byte) ([]byte, error) {
105103
fset := token.NewFileSet()
106104
file, sourceAdj, indentAdj, err := parse(fset, "", src, true)

package_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/*
2-
Copyright 2021 The GoPlus Authors (goplus.org)
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
6-
http://www.apache.org/licenses/LICENSE-2.0
7-
Unless required by applicable law or agreed to in writing, software
8-
distributed under the License is distributed on an "AS IS" BASIS,
9-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10-
See the License for the specific language governing permissions and
11-
limitations under the License.
2+
Copyright 2021 The GoPlus Authors (goplus.org)
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
1214
*/
1315

1416
package gogen_test

type_ext.go

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/*
2-
Copyright 2024 The GoPlus Authors (goplus.org)
3-
Licensed under the Apache License, Version 2.0 (the "License");
4-
you may not use this file except in compliance with the License.
5-
You may obtain a copy of the License at
6-
http://www.apache.org/licenses/LICENSE-2.0
7-
Unless required by applicable law or agreed to in writing, software
8-
distributed under the License is distributed on an "AS IS" BASIS,
9-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10-
See the License for the specific language governing permissions and
11-
limitations under the License.
2+
Copyright 2024 The GoPlus Authors (goplus.org)
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
1214
*/
1315

1416
package gogen
@@ -165,14 +167,25 @@ func Lookup(scope *types.Scope, name string) (obj types.Object) {
165167
// ----------------------------------------------------------------------------
166168

167169
var (
168-
TyByte = types.Universe.Lookup("byte").Type().(*types.Basic)
169-
TyRune = types.Universe.Lookup("rune").Type().(*types.Basic)
170+
TyByte *types.Basic
171+
TyRune *types.Basic
172+
173+
TyError types.Type
174+
TyAny types.Type
175+
TyEmptyInterface types.Type
170176
)
171177

172-
var (
178+
func init() {
179+
universe := types.Universe
180+
iotaObj = universe.Lookup("iota")
181+
TyByte = universe.Lookup("byte").Type().(*types.Basic)
182+
TyRune = universe.Lookup("rune").Type().(*types.Basic)
183+
TyError = universe.Lookup("error").Type()
184+
TyAny = universe.Lookup("any").Type()
173185
TyEmptyInterface = types.NewInterfaceType(nil, nil)
174-
TyError = types.Universe.Lookup("error").Type()
175-
)
186+
}
187+
188+
// ----------------------------------------------------------------------------
176189

177190
// refType: &T
178191
type refType struct {

0 commit comments

Comments
 (0)