File tree 3 files changed +15
-22
lines changed
3 files changed +15
-22
lines changed Original file line number Diff line number Diff line change @@ -15,11 +15,10 @@ import (
15
15
// It will never be created by go/types.
16
16
type Alias struct {}
17
17
18
- func (* Alias ) String () string { panic ("unreachable" ) }
19
-
18
+ func (* Alias ) String () string { panic ("unreachable" ) }
20
19
func (* Alias ) Underlying () types.Type { panic ("unreachable" ) }
21
-
22
- func ( * Alias ) Obj () * types.TypeName { panic ("unreachable" ) }
20
+ func ( * Alias ) Obj () * types. TypeName { panic ( "unreachable" ) }
21
+ func Rhs ( alias * Alias ) types.Type { panic ("unreachable" ) }
23
22
24
23
// Unalias returns the type t for go <=1.21.
25
24
func Unalias (t types.Type ) types.Type { return t }
Original file line number Diff line number Diff line change @@ -17,6 +17,17 @@ import (
17
17
// Alias is an alias of types.Alias.
18
18
type Alias = types.Alias
19
19
20
+ // Rhs returns the type on the right-hand side of the alias declaration.
21
+ func Rhs (alias * Alias ) types.Type {
22
+ if alias , ok := any (alias ).(interface { Rhs () types.Type }); ok {
23
+ return alias .Rhs () // go1.23+
24
+ }
25
+
26
+ // go1.22's Alias didn't have the Rhs method,
27
+ // so Unalias is the best we can do.
28
+ return Unalias (alias )
29
+ }
30
+
20
31
// Unalias is a wrapper of types.Unalias.
21
32
func Unalias (t types.Type ) types.Type { return types .Unalias (t ) }
22
33
Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ import (
21
21
"sort"
22
22
"strconv"
23
23
"strings"
24
- "unsafe"
25
24
26
25
"golang.org/x/tools/go/types/objectpath"
27
26
"golang.org/x/tools/internal/aliases"
@@ -529,7 +528,7 @@ func (p *iexporter) doDecl(obj types.Object) {
529
528
if alias , ok := t .(* aliases.Alias ); ok {
530
529
// Preserve materialized aliases,
531
530
// even of non-exported types.
532
- t = aliasRHS (alias )
531
+ t = aliases . Rhs (alias )
533
532
}
534
533
w .typ (t , obj .Pkg ())
535
534
break
@@ -1331,19 +1330,3 @@ func (e internalError) Error() string { return "gcimporter: " + string(e) }
1331
1330
func internalErrorf (format string , args ... interface {}) error {
1332
1331
return internalError (fmt .Sprintf (format , args ... ))
1333
1332
}
1334
-
1335
- // aliasRHS removes exactly one Alias constructor.
1336
- func aliasRHS (alias * aliases.Alias ) types.Type {
1337
- // TODO(adonovan): if proposal #66559 is accepted, this will
1338
- // become Alias.RHS(alias). In the meantime, we must punch
1339
- // through the drywall.
1340
- type go123Alias struct {
1341
- _ * types.TypeName
1342
- _ * types.TypeParamList
1343
- RHS types.Type
1344
- _ types.Type
1345
- }
1346
- var raw * go123Alias
1347
- * (* * aliases .Alias )(unsafe .Pointer (& raw )) = alias
1348
- return raw .RHS
1349
- }
You can’t perform that action at this time.
0 commit comments