@@ -145,13 +145,13 @@ func (fo functionName) Hash(h *fingerprint.Hasher) error {
145145}
146146
147147type signature struct {
148- Arguments []typed.TypeName
149- Results []typed.TypeName
148+ Arguments []* typed.NamedType
149+ Results []* typed.NamedType
150150}
151151
152152// Signature matches function declarations based on their arguments and return
153153// value types.
154- func Signature (args []typed.TypeName , ret []typed.TypeName ) FunctionOption {
154+ func Signature (args []* typed.NamedType , ret []* typed.NamedType ) FunctionOption {
155155 return & signature {Arguments : args , Results : ret }
156156}
157157
@@ -225,8 +225,8 @@ func (fo *signature) evaluate(info functionInformation) bool {
225225func (fo * signature ) Hash (h * fingerprint.Hasher ) error {
226226 return h .Named (
227227 "signature" ,
228- fingerprint.List [typed.TypeName ](fo .Arguments ),
229- fingerprint.List [typed.TypeName ](fo .Results ),
228+ fingerprint.List [* typed.NamedType ](fo .Arguments ),
229+ fingerprint.List [* typed.NamedType ](fo .Results ),
230230 )
231231}
232232
@@ -236,15 +236,15 @@ type signatureContains struct {
236236
237237// SignatureContains matches function declarations based on their arguments and
238238// return value types in any order and does not require all arguments or return values to be present.
239- func SignatureContains (args []typed.TypeName , ret []typed.TypeName ) FunctionOption {
239+ func SignatureContains (args []* typed.NamedType , ret []* typed.NamedType ) FunctionOption {
240240 return & signatureContains {signature {Arguments : args , Results : ret }}
241241}
242242
243243func (fo * signatureContains ) Hash (h * fingerprint.Hasher ) error {
244244 return h .Named (
245245 "signature-contains" ,
246- fingerprint.List [typed.TypeName ](fo .Arguments ),
247- fingerprint.List [typed.TypeName ](fo .Results ),
246+ fingerprint.List [* typed.NamedType ](fo .Arguments ),
247+ fingerprint.List [* typed.NamedType ](fo .Results ),
248248 )
249249}
250250
@@ -262,7 +262,7 @@ func (fo *signatureContains) evaluate(info functionInformation) bool {
262262
263263// containsAnyType checks if any of the expected types match any of the actual types in the field list.
264264// Returns false if either slice is empty or nil.
265- func containsAnyType (expectedTypes []typed.TypeName , fieldList * dst.FieldList ) bool {
265+ func containsAnyType (expectedTypes []* typed.NamedType , fieldList * dst.FieldList ) bool {
266266 // Quick return if either side is empty.
267267 if len (expectedTypes ) == 0 || fieldList == nil || len (fieldList .List ) == 0 {
268268 return false
@@ -281,10 +281,10 @@ func containsAnyType(expectedTypes []typed.TypeName, fieldList *dst.FieldList) b
281281}
282282
283283type receiver struct {
284- TypeName typed.TypeName
284+ TypeName * typed.NamedType
285285}
286286
287- func Receiver (typeName typed.TypeName ) FunctionOption {
287+ func Receiver (typeName * typed.NamedType ) FunctionOption {
288288 return & receiver {typeName }
289289}
290290
@@ -393,18 +393,18 @@ func (_ *resultImplements) fileMayMatch(_ *may.FileContext) may.MatchType {
393393
394394// evaluateFieldListImplements checks if any field in the list matches the interfaceName,
395395// either by exact type name or by interface implementation.
396- func evaluateFieldListImplements (fields * dst.FieldList , interfaceName string , info functionInformation ) bool {
396+ func evaluateFieldListImplements (typeResolver typeResolver , fields * dst.FieldList , interfaceName string ) bool {
397397 if fields == nil || len (fields .List ) == 0 {
398398 return false
399399 }
400400
401401 // Optimization: First, check for an exact match using the helper.
402- if _ , found := typed .FindMatchingTypeName (fields , interfaceName ); found {
402+ if _ , found := typed .FindMatchingType (fields , interfaceName ); found {
403403 return true // Found direct match
404404 }
405405
406406 // If no exact match, check implementation (requires type resolver).
407- if info . typeResolver == nil {
407+ if typeResolver == nil {
408408 return false // Cannot check implementation without resolver.
409409 }
410410
@@ -414,7 +414,7 @@ func evaluateFieldListImplements(fields *dst.FieldList, interfaceName string, in
414414 }
415415
416416 for _ , field := range fields .List {
417- if typed .ExprImplements (info . typeResolver , field .Type , targetInterface ) {
417+ if typed .ExprImplements (typeResolver , field .Type , targetInterface ) {
418418 return true // Found an implementing type.
419419 }
420420 }
@@ -423,7 +423,7 @@ func evaluateFieldListImplements(fields *dst.FieldList, interfaceName string, in
423423}
424424
425425func (fo * resultImplements ) evaluate (info functionInformation ) bool {
426- return evaluateFieldListImplements (info .Type .Results , fo .InterfaceName , info )
426+ return evaluateFieldListImplements (info .typeResolver , info . Type .Results , fo .InterfaceName )
427427}
428428
429429func (fo * resultImplements ) Hash (h * fingerprint.Hasher ) error {
@@ -467,10 +467,10 @@ func (fo *finalResultImplements) evaluate(info functionInformation) bool {
467467 return false
468468 }
469469
470- // Optimization: First, check for an exact match using TypeName parsing.
471- if tn , err := typed .NewTypeName (fo .InterfaceName ); err == nil {
470+ // Optimization: First, check for an exact match using Type parsing.
471+ if t , err := typed .NewType (fo .InterfaceName ); err == nil {
472472 lastField := info .Type .Results .List [len (info .Type .Results .List )- 1 ]
473- if tn .Matches (lastField .Type ) {
473+ if t .Matches (lastField .Type ) {
474474 return true // Found direct match
475475 }
476476 } // If parsing failed or no match, fall through to type resolution.
@@ -508,11 +508,9 @@ func ArgumentImplements(interfaceName string) FunctionOption {
508508 return & argumentImplements {InterfaceName : interfaceName }
509509}
510510
511- func (fo * argumentImplements ) impliesImported () []string {
512- pkgPath , _ := typed .SplitPackageAndName (fo .InterfaceName )
513- if pkgPath != "" {
514- return []string {pkgPath }
515- }
511+ func (* argumentImplements ) impliesImported () []string {
512+ // A type can implement an interface without importing the interface's package
513+ // due to Go's structural typing system.
516514 return nil
517515}
518516
@@ -530,7 +528,7 @@ func (_ *argumentImplements) fileMayMatch(_ *may.FileContext) may.MatchType {
530528}
531529
532530func (fo * argumentImplements ) evaluate (info functionInformation ) bool {
533- return evaluateFieldListImplements (info .Type .Params , fo .InterfaceName , info )
531+ return evaluateFieldListImplements (info .typeResolver , info . Type .Params , fo .InterfaceName )
534532}
535533
536534func (fo * argumentImplements ) Hash (h * fingerprint.Hasher ) error {
@@ -590,9 +588,9 @@ func (o *unmarshalFuncDeclOption) UnmarshalYAML(ctx gocontext.Context, node ast.
590588 if err := yaml .NodeToValueContext (ctx , mapping .Values [0 ].Value , & arg ); err != nil {
591589 return err
592590 }
593- tn , err := typed .NewTypeName (arg )
591+ tn , err := typed .NewNamedType (arg )
594592 if err != nil {
595- return err
593+ return fmt . Errorf ( "invalid receiver type %q: %w" , arg , err )
596594 }
597595 o .FunctionOption = Receiver (tn )
598596 case "signature" , "signature-contains" :
@@ -614,25 +612,27 @@ func (o *unmarshalFuncDeclOption) UnmarshalYAML(ctx gocontext.Context, node ast.
614612 return fmt .Errorf ("unexpected keys: %s" , strings .Join (keys , ", " ))
615613 }
616614
617- var args []typed.TypeName
615+ var args []* typed.NamedType
618616 if len (sig .Args ) > 0 {
619- args = make ([]typed.TypeName , len (sig .Args ))
617+ args = make ([]* typed.NamedType , len (sig .Args ))
620618 for i , a := range sig .Args {
621- var err error
622- if args [ i ], err = typed . NewTypeName ( a ); err != nil {
623- return err
619+ tn , err := typed . NewNamedType ( a )
620+ if err != nil {
621+ return fmt . Errorf ( "invalid argument type %q at position %d: %w" , a , i , err )
624622 }
623+ args [i ] = tn
625624 }
626625 }
627626
628- var ret []typed.TypeName
627+ var ret []* typed.NamedType
629628 if len (sig .Ret ) > 0 {
630- ret = make ([]typed.TypeName , len (sig .Ret ))
629+ ret = make ([]* typed.NamedType , len (sig .Ret ))
631630 for i , r := range sig .Ret {
632- var err error
633- if ret [ i ], err = typed . NewTypeName ( r ); err != nil {
634- return err
631+ tn , err := typed . NewNamedType ( r )
632+ if err != nil {
633+ return fmt . Errorf ( "invalid return type %q at position %d: %w" , r , i , err )
635634 }
635+ ret [i ] = tn
636636 }
637637 }
638638
0 commit comments