pos := r.pos()
switch tag {
- case 'A':
- typ := r.typ()
-
- r.declare(types2.NewTypeName(pos, r.currPkg, name, typ))
+ case 'A', 'B':
+ var tparams []*types2.TypeParam
+ if tag == 'B' {
+ tparams = r.tparamList()
+ }
+ rhs := r.typ()
+ const enabled = true // This is now always enabled within the compiler.
+ r.declare(newAliasTypeName(enabled, pos, r.currPkg, name, rhs, tparams))
case 'C':
typ, val := r.value()
case pkgbits.ObjAlias:
pos := r.pos()
+ var tparams []*types2.TypeParam // TODO(#68778): Read tparams for unified IR.
typ := r.typ()
- return newAliasTypeName(pr.enableAlias, pos, objPkg, objName, typ)
+ return newAliasTypeName(pr.enableAlias, pos, objPkg, objName, typ, tparams)
case pkgbits.ObjConst:
pos := r.pos()
}
// newAliasTypeName returns a new TypeName, with a materialized *types2.Alias if supported.
-func newAliasTypeName(aliases bool, pos syntax.Pos, pkg *types2.Package, name string, rhs types2.Type) *types2.TypeName {
+func newAliasTypeName(aliases bool, pos syntax.Pos, pkg *types2.Package, name string, rhs types2.Type, tparams []*types2.TypeParam) *types2.TypeName {
// Copied from x/tools/internal/aliases.NewAlias via
// GOROOT/src/go/internal/gcimporter/ureader.go.
if aliases {
tname := types2.NewTypeName(pos, pkg, name, nil)
- _ = types2.NewAlias(tname, rhs) // form TypeName -> Alias cycle
+ a := types2.NewAlias(tname, rhs) // form TypeName -> Alias cycle
+ a.SetTypeParams(tparams)
return tname
}
+ assert(len(tparams) == 0)
return types2.NewTypeName(pos, pkg, name, rhs)
}
// }
//
// type Alias struct {
-// Tag byte // 'A'
+// Tag byte // 'A' or 'B'
// Pos Pos
+// TypeParams []typeOff // only present if Tag == 'B'
// Type typeOff
// }
//
pos := r.pos()
switch tag {
- case 'A':
- typ := r.typ()
-
- r.declare(types.NewTypeName(pos, r.currPkg, name, typ))
+ case 'A', 'B':
+ var tparams []*types.TypeParam
+ if tag == 'B' {
+ tparams = r.tparamList()
+ }
+ rhs := r.typ()
+ r.declare(newAliasTypeName(pos, r.currPkg, name, rhs, tparams))
case 'C':
typ, val := r.value()
case pkgbits.ObjAlias:
pos := r.pos()
+ var tparams []*types.TypeParam // TODO(#68778): Read tparams for unified IR.
typ := r.typ()
- declare(newAliasTypeName(pos, objPkg, objName, typ))
+ declare(newAliasTypeName(pos, objPkg, objName, typ, tparams))
case pkgbits.ObjConst:
pos := r.pos()
}
// newAliasTypeName returns a new TypeName, with a materialized *types.Alias if supported.
-func newAliasTypeName(pos token.Pos, pkg *types.Package, name string, rhs types.Type) *types.TypeName {
+func newAliasTypeName(pos token.Pos, pkg *types.Package, name string, rhs types.Type, tparams []*types.TypeParam) *types.TypeName {
// When GODEBUG=gotypesalias=1 or unset, the Type() of the return value is a
// *types.Alias. Copied from x/tools/internal/aliases.NewAlias.
switch godebug.New("gotypesalias").Value() {
case "", "1":
tname := types.NewTypeName(pos, pkg, name, nil)
- _ = types.NewAlias(tname, rhs) // form TypeName -> Alias cycle
+ a := types.NewAlias(tname, rhs) // form TypeName -> Alias cycle
+ a.SetTypeParams(tparams)
return tname
}
+ assert(len(tparams) == 0)
return types.NewTypeName(pos, pkg, name, rhs)
}