@@ -126,6 +126,35 @@ func (k Kind) basicType() rawType {
126
126
return rawType (k << 1 )
127
127
}
128
128
129
+ // Copied from reflect/type.go
130
+ // https://go.dev/src/reflect/type.go?#L348
131
+
132
+ // ChanDir represents a channel type's direction.
133
+ type ChanDir int
134
+
135
+ const (
136
+ RecvDir ChanDir = 1 << iota // <-chan
137
+ SendDir // chan<-
138
+ BothDir = RecvDir | SendDir // chan
139
+ )
140
+
141
+ // Method represents a single method.
142
+ type Method struct {
143
+ // Name is the method name.
144
+ Name string
145
+
146
+ // PkgPath is the package path that qualifies a lower case (unexported)
147
+ // method name. It is empty for upper case (exported) method names.
148
+ // The combination of PkgPath and Name uniquely identifies a method
149
+ // in a method set.
150
+ // See https://golang.org/ref/spec#Uniqueness_of_identifiers
151
+ PkgPath string
152
+
153
+ Type Type // method type
154
+ Func Value // func with receiver as first argument
155
+ Index int // index for Type.Method
156
+ }
157
+
129
158
// The following Type type has been copied almost entirely from
130
159
// https://github.com/golang/go/blob/go1.15/src/reflect/type.go#L27-L212.
131
160
// Some methods have been commented out as they haven't yet been implemented.
@@ -173,7 +202,7 @@ type Type interface {
173
202
//
174
203
// For an interface type, the returned Method's Type field gives the
175
204
// method signature, without a receiver, and the Func field is nil.
176
- // MethodByName(string) (Method, bool)
205
+ MethodByName (string ) (Method , bool )
177
206
178
207
// NumMethod returns the number of exported methods in the type's method set.
179
208
NumMethod () int
@@ -187,7 +216,7 @@ type Type interface {
187
216
// If the type was predeclared (string, error) or not defined (*T, struct{},
188
217
// []int, or A where A is an alias for a non-defined type), the package path
189
218
// will be the empty string.
190
- // PkgPath() string
219
+ PkgPath () string
191
220
192
221
// Size returns the number of bytes needed to store
193
222
// a value of the given type; it is analogous to unsafe.Sizeof.
@@ -234,7 +263,7 @@ type Type interface {
234
263
235
264
// ChanDir returns a channel type's direction.
236
265
// It panics if the type's Kind is not Chan.
237
- // ChanDir() ChanDir
266
+ ChanDir () ChanDir
238
267
239
268
// IsVariadic reports whether a function type's final input parameter
240
269
// is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's
@@ -248,7 +277,7 @@ type Type interface {
248
277
// t.IsVariadic() == true
249
278
//
250
279
// IsVariadic panics if the type's Kind is not Func.
251
- // IsVariadic() bool
280
+ IsVariadic () bool
252
281
253
282
// Elem returns a type's element type.
254
283
// It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.
@@ -267,7 +296,7 @@ type Type interface {
267
296
268
297
// FieldByName returns the struct field with the given name
269
298
// and a boolean indicating if the field was found.
270
- // FieldByName(name string) (StructField, bool)
299
+ FieldByName (name string ) (StructField , bool )
271
300
272
301
// FieldByNameFunc returns the struct field with a name
273
302
// that satisfies the match function and a boolean indicating if
@@ -286,7 +315,7 @@ type Type interface {
286
315
// In returns the type of a function type's i'th input parameter.
287
316
// It panics if the type's Kind is not Func.
288
317
// It panics if i is not in the range [0, NumIn()).
289
- // In(i int) Type
318
+ In (i int ) Type
290
319
291
320
// Key returns a map type's key type.
292
321
// It panics if the type's Kind is not Map.
@@ -302,16 +331,16 @@ type Type interface {
302
331
303
332
// NumIn returns a function type's input parameter count.
304
333
// It panics if the type's Kind is not Func.
305
- // NumIn() int
334
+ NumIn () int
306
335
307
336
// NumOut returns a function type's output parameter count.
308
337
// It panics if the type's Kind is not Func.
309
- // NumOut() int
338
+ NumOut () int
310
339
311
340
// Out returns the type of a function type's i'th output parameter.
312
341
// It panics if the type's Kind is not Func.
313
342
// It panics if i is not in the range [0, NumOut()).
314
- // Out(i int) Type
343
+ Out (i int ) Type
315
344
}
316
345
317
346
// The typecode as used in an interface{}.
@@ -675,10 +704,26 @@ func (t rawType) Comparable() bool {
675
704
}
676
705
}
677
706
707
+ func (t rawType ) ChanDir () ChanDir {
708
+ panic ("unimplemented: (reflect.Type).ChanDir()" )
709
+ }
710
+
678
711
func (t rawType ) ConvertibleTo (u Type ) bool {
679
712
panic ("unimplemented: (reflect.Type).ConvertibleTo()" )
680
713
}
681
714
715
+ func (t rawType ) IsVariadic () bool {
716
+ panic ("unimplemented: (reflect.Type).IsVariadic()" )
717
+ }
718
+
719
+ func (t rawType ) NumIn () int {
720
+ panic ("unimplemented: (reflect.Type).NumIn()" )
721
+ }
722
+
723
+ func (t rawType ) NumOut () int {
724
+ panic ("unimplemented: (reflect.Type).NumOut()" )
725
+ }
726
+
682
727
func (t rawType ) NumMethod () int {
683
728
panic ("unimplemented: (reflect.Type).NumMethod()" )
684
729
}
@@ -691,6 +736,26 @@ func (t rawType) Key() Type {
691
736
panic ("unimplemented: (reflect.Type).Key()" )
692
737
}
693
738
739
+ func (t rawType ) In (i int ) Type {
740
+ panic ("unimplemented: (reflect.Type).In()" )
741
+ }
742
+
743
+ func (t rawType ) Out (i int ) Type {
744
+ panic ("unimplemented: (reflect.Type).Out()" )
745
+ }
746
+
747
+ func (t rawType ) MethodByName (name string ) (Method , bool ) {
748
+ panic ("unimplemented: (reflect.Type).MethodByName()" )
749
+ }
750
+
751
+ func (t rawType ) PkgPath () string {
752
+ panic ("unimplemented: (reflect.Type).PkgPath()" )
753
+ }
754
+
755
+ func (t rawType ) FieldByName (name string ) (StructField , bool ) {
756
+ panic ("unimplemented: (reflect.Type).FieldByName()" )
757
+ }
758
+
694
759
// A StructField describes a single field in a struct.
695
760
type StructField struct {
696
761
// Name indicates the field name.
@@ -704,6 +769,7 @@ type StructField struct {
704
769
Tag StructTag // field tag string
705
770
Anonymous bool
706
771
Offset uintptr
772
+ Index []int // index sequence for Type.FieldByIndex
707
773
}
708
774
709
775
// IsExported reports whether the field is exported.
@@ -800,3 +866,7 @@ func (e *TypeError) Error() string {
800
866
func align (offset uintptr , alignment uintptr ) uintptr {
801
867
return (offset + alignment - 1 ) &^ (alignment - 1 )
802
868
}
869
+
870
+ func SliceOf (t Type ) Type {
871
+ panic ("unimplemented: reflect.SliceOf()" )
872
+ }
0 commit comments