@@ -14,6 +14,20 @@ import (
1414 "github.com/DataDog/orchestrion/internal/fingerprint"
1515)
1616
17+ // Common built-in type definitions for convenience.
18+ // These pre-defined TypeName instances help avoid repeated string literals
19+ // and potential typos when referring to common Go built-in types.
20+ var (
21+ // Basic types currently used in the codebase
22+ Any = MustTypeName ("any" )
23+ Bool = MustTypeName ("bool" )
24+ String = MustTypeName ("string" )
25+ // Uncomment these when we used.
26+ // Byte = MustTypeName("byte")
27+ // Int = MustTypeName("int")
28+ // Error = MustTypeName("error")
29+ )
30+
1731// TypeName represents a parsed Go type name, potentially including a package path and pointer indicator.
1832type TypeName struct {
1933 // ImportPath is the import Path that provides the type, or an empty string if the
@@ -35,13 +49,13 @@ func NewTypeName(n string) (tn TypeName, err error) {
3549 matches := typeNameRe .FindStringSubmatch (n )
3650 if matches == nil {
3751 err = fmt .Errorf ("invalid TypeName syntax: %q" , n )
38- return
52+ return tn , err
3953 }
4054
4155 tn .Pointer = matches [1 ] == "*"
4256 tn .ImportPath = matches [2 ]
4357 tn .Name = matches [3 ]
44- return
58+ return tn , nil
4559}
4660
4761// MustTypeName is the same as NewTypeName, except it panics in case of an error.
@@ -50,7 +64,7 @@ func MustTypeName(n string) (tn TypeName) {
5064 if tn , err = NewTypeName (n ); err != nil {
5165 panic (err )
5266 }
53- return
67+ return tn
5468}
5569
5670// Matches determines whether the provided AST expression node represents the same type
0 commit comments