diff options
| author | Marc Vertes <mvertes@free.fr> | 2025-03-03 10:49:27 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2025-03-03 10:49:27 +0100 |
| commit | ab69cd9ba61092650abdff6484b12021182385ce (patch) | |
| tree | 4805a0365fc481df57c8f0b5d45f7f993b9a0ef9 /vm/type.go | |
| parent | dabd9e5eb81bbc9aeaeb32fb3e3ce83eef258a77 (diff) | |
fix: improve structparscan-struct
Use 'unsafe' to modify private struct fields, allowing to keep
unmodified field names: before they were prefixed with a capital.
Parse package statement. Provide a also a default package name for
REPL and tests. The support of packages is still incomplete.
Diffstat (limited to 'vm/type.go')
| -rw-r--r-- | vm/type.go | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -6,12 +6,16 @@ import "reflect" // Type is the representation of a runtime type. type Type struct { - Name string - Rtype reflect.Type + PkgPath string + Name string + Rtype reflect.Type } func (t *Type) String() string { if t.Name != "" { + if t.PkgPath != "" { + return t.PkgPath + "." + t.Name + } return t.Name } return t.Rtype.String() @@ -84,7 +88,8 @@ func FuncOf(arg, ret []*Type, variadic bool) *Type { func StructOf(fields []*Type) *Type { rf := make([]reflect.StructField, len(fields)) for i, f := range fields { - rf[i].Name = "X" + f.Name + rf[i].Name = f.Name + rf[i].PkgPath = f.PkgPath rf[i].Type = f.Rtype } return &Type{Rtype: reflect.StructOf(rf)} |
