Skip to content

Commit

Permalink
Merge pull request #1484 from xushiwei/q
Browse files Browse the repository at this point in the history
toIdentType: rec.Use
  • Loading branch information
xushiwei committed Oct 21, 2023
2 parents caf1d4b + 3707f9b commit dc26c66
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@ func (f *File) NoEntrypoint() bool {
return f.ShadowEntry != nil
}

// HasPkgDecl checks if `package xxx` exists or not.
func (f *File) HasPkgDecl() bool {
return f.Package != token.NoPos
}

// Pos returns position of first character belonging to the node.
func (f *File) Pos() token.Pos {
if f.Package != token.NoPos {
Expand Down
10 changes: 6 additions & 4 deletions cl/func_type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,17 @@ Name context:
// ---------------------------------------------------------------------------*/

func toIdentType(ctx *blockCtx, ident *ast.Ident) (ret types.Type) {
var obj types.Object
if rec := ctx.recorder(); rec != nil {
defer func() {
if n, ok := ret.(interface {
Obj() *types.TypeName
}); ok {
rec.Use(ident, n.Obj())
if obj != nil {
rec.Use(ident, obj)
}
}()
}
if ctx.tlookup != nil {
if typ := ctx.tlookup.Lookup(ident.Name); typ != nil {
obj = typ.Obj()
return typ
}
}
Expand All @@ -244,10 +244,12 @@ func toIdentType(ctx *blockCtx, ident *ast.Ident) (ret types.Type) {
return types.Typ[types.Invalid]
}
if t, ok := v.(*types.TypeName); ok {
obj = t
return t.Type()
}
if v, _ := lookupPkgRef(ctx, nil, ident, objPkgRef); v != nil {
if t, ok := v.(*types.TypeName); ok {
obj = t
return t.Type()
}
}
Expand Down
2 changes: 1 addition & 1 deletion cl/typeparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type typeParamLookup struct {
typeParams []*types.TypeParam
}

func (p *typeParamLookup) Lookup(name string) types.Type {
func (p *typeParamLookup) Lookup(name string) *types.TypeParam {
for _, t := range p.typeParams {
tname := t.Obj().Name()
if tname != "_" && name == tname {
Expand Down

0 comments on commit dc26c66

Please sign in to comment.