Skip to content

Commit 039e60c

Browse files
committed
go/types: revert user-visible changes related to aliases
Reason: Decision to back out current alias implementation. For #16339 (comment). Change-Id: Ie04f24e529db2d29c5dd2e36413f5f37f628df39 Reviewed-on: https://go-review.googlesource.com/32819 Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 2c6949e commit 039e60c

File tree

7 files changed

+46
-38
lines changed

7 files changed

+46
-38
lines changed

src/go/internal/gcimporter/bimport.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ func (p *importer) obj(tag int) {
284284
if pkg, name := p.qualifiedName(); pkg != nil {
285285
orig = pkg.Scope().Lookup(name)
286286
}
287-
p.declare(types.NewAlias(pos, p.pkgList[0], name, orig))
287+
// Alias-related code. Keep for now.
288+
_ = pos
289+
_ = name
290+
_ = orig
291+
// p.declare(types.NewAlias(pos, p.pkgList[0], name, orig))
288292

289293
default:
290294
errorf("unexpected object tag %d", tag)

src/go/types/api_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import (
1212
"go/parser"
1313
"go/token"
1414
"internal/testenv"
15-
"os"
16-
"os/exec"
17-
"path/filepath"
1815
"reflect"
1916
"regexp"
2017
"strings"
@@ -1299,6 +1296,8 @@ func f(x int) { y := x; print(y) }
12991296
}
13001297
}
13011298

1299+
// Alias-related code. Keep for now.
1300+
/*
13021301
func TestAliases(t *testing.T) {
13031302
testenv.MustHaveGoBuild(t)
13041303
@@ -1447,3 +1446,4 @@ var _ = Implements(nil, nil)
14471446
t.Errorf("missing aliases: %v", defs)
14481447
}
14491448
}
1449+
*/

src/go/types/check_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var tests = [][]string{
7272
{"testdata/const1.src"},
7373
{"testdata/constdecl.src"},
7474
{"testdata/vardecl.src"},
75-
{"testdata/aliasdecl.src"},
75+
//{"testdata/aliasdecl.src"},
7676
{"testdata/expr0.src"},
7777
{"testdata/expr1.src"},
7878
{"testdata/expr2.src"},

src/go/types/decl.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
8585
case *Func:
8686
// functions may be recursive - no need to track dependencies
8787
check.funcDecl(obj, d)
88-
case *Alias:
89-
// aliases cannot be recursive - no need to track dependencies
90-
check.aliasDecl(obj, d)
88+
// Alias-related code. Keep for now.
89+
// case *Alias:
90+
// // aliases cannot be recursive - no need to track dependencies
91+
// check.aliasDecl(obj, d)
9192
default:
9293
unreachable()
9394
}
@@ -337,17 +338,17 @@ func (check *Checker) funcDecl(obj *Func, decl *declInfo) {
337338
// but it may be nil.
338339
func original(obj Object) Object {
339340
// an alias stands for the original object; use that one instead
340-
if alias, _ := obj.(*Alias); alias != nil {
341+
if alias, _ := obj.(*disabledAlias); alias != nil {
341342
obj = alias.orig
342343
// aliases always refer to non-alias originals
343-
if _, ok := obj.(*Alias); ok {
344+
if _, ok := obj.(*disabledAlias); ok {
344345
panic("original is an alias")
345346
}
346347
}
347348
return obj
348349
}
349350

350-
func (check *Checker) aliasDecl(obj *Alias, decl *declInfo) {
351+
func (check *Checker) aliasDecl(obj *disabledAlias, decl *declInfo) {
351352
assert(obj.typ == nil)
352353

353354
// alias declarations cannot use iota

src/go/types/object.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,26 +216,26 @@ func (obj *Func) Scope() *Scope { return obj.typ.(*Signature).scope }
216216
func (*Func) isDependency() {} // a function may be a dependency of an initialization expression
217217

218218
// An Alias represents a declared alias.
219-
type Alias struct {
219+
type disabledAlias struct {
220220
object
221221
orig Object // aliased constant, type, variable, or function; never an alias
222222
kind token.Token // token.CONST, token.TYPE, token.VAR, or token.FUNC (only needed during resolve phase)
223223
}
224224

225-
func NewAlias(pos token.Pos, pkg *Package, name string, orig Object) *Alias {
225+
func disabledNewAlias(pos token.Pos, pkg *Package, name string, orig Object) *disabledAlias {
226226
var typ Type = Typ[Invalid]
227227
if orig != nil {
228228
typ = orig.Type()
229229
}
230230
// No need to set a valid Alias.kind - that field is only used during identifier
231231
// resolution (1st type-checker pass). We could store the field outside but it's
232232
// easier to keep it here.
233-
return &Alias{object{nil, pos, pkg, name, typ, 0, token.NoPos}, orig, token.ILLEGAL}
233+
return &disabledAlias{object{nil, pos, pkg, name, typ, 0, token.NoPos}, orig, token.ILLEGAL}
234234
}
235235

236236
// Orig returns the aliased object, or nil if there was an error.
237237
// The returned object is never an Alias.
238-
func (obj *Alias) Orig() Object { return obj.orig }
238+
func (obj *disabledAlias) disabledOrig() Object { return obj.orig }
239239

240240
// A Label represents a declared label.
241241
type Label struct {
@@ -295,8 +295,9 @@ func writeObject(buf *bytes.Buffer, obj Object, qf Qualifier) {
295295
}
296296
return
297297

298-
case *Alias:
299-
buf.WriteString("alias")
298+
// Alias-related code. Keep for now.
299+
// case *Alias:
300+
// buf.WriteString("alias")
300301

301302
case *Label:
302303
buf.WriteString("label")
@@ -352,15 +353,15 @@ func ObjectString(obj Object, qf Qualifier) string {
352353
return buf.String()
353354
}
354355

355-
func (obj *PkgName) String() string { return ObjectString(obj, nil) }
356-
func (obj *Const) String() string { return ObjectString(obj, nil) }
357-
func (obj *TypeName) String() string { return ObjectString(obj, nil) }
358-
func (obj *Var) String() string { return ObjectString(obj, nil) }
359-
func (obj *Func) String() string { return ObjectString(obj, nil) }
360-
func (obj *Alias) String() string { return ObjectString(obj, nil) }
361-
func (obj *Label) String() string { return ObjectString(obj, nil) }
362-
func (obj *Builtin) String() string { return ObjectString(obj, nil) }
363-
func (obj *Nil) String() string { return ObjectString(obj, nil) }
356+
func (obj *PkgName) String() string { return ObjectString(obj, nil) }
357+
func (obj *Const) String() string { return ObjectString(obj, nil) }
358+
func (obj *TypeName) String() string { return ObjectString(obj, nil) }
359+
func (obj *Var) String() string { return ObjectString(obj, nil) }
360+
func (obj *Func) String() string { return ObjectString(obj, nil) }
361+
func (obj *disabledAlias) String() string { return ObjectString(obj, nil) }
362+
func (obj *Label) String() string { return ObjectString(obj, nil) }
363+
func (obj *Builtin) String() string { return ObjectString(obj, nil) }
364+
func (obj *Nil) String() string { return ObjectString(obj, nil) }
364365

365366
func writeFuncName(buf *bytes.Buffer, f *Func, qf Qualifier) {
366367
if f.typ != nil {

src/go/types/resolver.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,12 @@ func (check *Checker) collectObjects() {
274274
check.declare(fileScope, nil, obj, token.NoPos)
275275
}
276276

277-
case *ast.AliasSpec:
278-
obj := NewAlias(s.Name.Pos(), pkg, s.Name.Name, nil)
279-
obj.typ = nil // unresolved
280-
obj.kind = d.Tok
281-
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, init: s.Orig})
277+
// Alias-related code. Keep for now.
278+
// case *ast.AliasSpec:
279+
// obj := NewAlias(s.Name.Pos(), pkg, s.Name.Name, nil)
280+
// obj.typ = nil // unresolved
281+
// obj.kind = d.Tok
282+
// check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, init: s.Orig})
282283

283284
case *ast.ValueSpec:
284285
switch d.Tok {

src/go/types/typexpr.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeNa
4545
delete(check.unusedDotImports[scope], pkg)
4646
}
4747

48+
// Alias-related code. Keep for now.
4849
// An alias stands for the original object; use that one instead.
4950
// TODO(gri) We should be able to factor out the Typ[Invalid] test.
50-
if alias, _ := obj.(*Alias); alias != nil {
51-
obj = original(obj)
52-
if obj == nil || typ == Typ[Invalid] {
53-
return
54-
}
55-
assert(typ == obj.Type())
56-
}
51+
// if alias, _ := obj.(*Alias); alias != nil {
52+
// obj = original(obj)
53+
// if obj == nil || typ == Typ[Invalid] {
54+
// return
55+
// }
56+
// assert(typ == obj.Type())
57+
// }
5758

5859
switch obj := obj.(type) {
5960
case *PkgName:

0 commit comments

Comments
 (0)