From f60b67e7665b56271b2c485001db78912e2c487c Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Sun, 25 Oct 2026 11:06:19 +0100 Subject: [PATCH] fix(gs): register override struct types under their qualified names About thirty override struct types, such as strings.Builder, bytes.Buffer, fs.PathError and atomic.Value, were registered under bare names (Builder, Buffer, ...), while the compiler and reflect look types up by their Go type strings. Reflection then found no methods for them, and strings.Reader and bytes.Reader shared one registry entry. They are now registered as pkg.Name, like the other override types. Signed-off-by: Randall C. O'Reilly --- gs/bytes/buffer.gs.ts | 2 +- gs/bytes/reader.gs.ts | 2 +- gs/github.com/pkg/errors/errors.ts | 6 ++--- gs/io/fs/fs.ts | 2 +- gs/io/fs/readdir.ts | 2 +- gs/io/fs/sub.ts | 4 +-- gs/os/dir_unix.gs.ts | 2 +- gs/os/error.gs.ts | 2 +- gs/os/exec.gs.ts | 8 +++--- gs/os/exec_posix.gs.ts | 2 +- gs/os/root_js.gs.ts | 2 +- gs/os/types_unix.gs.ts | 2 +- gs/path/path.ts | 2 +- gs/strconv/atoi.gs.ts | 2 +- gs/strings/builder.ts | 2 +- gs/strings/reader.ts | 2 +- gs/strings/replace.ts | 2 +- gs/sync/atomic/type.gs.ts | 8 +++--- gs/sync/atomic/value.gs.ts | 4 +-- .../reflect_override_method_sets/expected.log | 3 +++ .../reflect_override_method_sets.go | 9 +++++++ .../reflect_override_method_sets.gs.ts | 27 +++++++++++++++++++ 22 files changed, 68 insertions(+), 29 deletions(-) diff --git a/gs/bytes/buffer.gs.ts b/gs/bytes/buffer.gs.ts index 72e1e1a62..292d53a51 100644 --- a/gs/bytes/buffer.gs.ts +++ b/gs/bytes/buffer.gs.ts @@ -579,7 +579,7 @@ export class Buffer { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Buffer', + 'bytes.Buffer', new Buffer(), [{ name: "Bytes", args: [], returns: [{ type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }] }, { name: "AvailableBuffer", args: [], returns: [{ type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }] }, { name: "String", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "empty", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Len", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Cap", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Available", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Truncate", args: [{ name: "n", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [] }, { name: "Reset", args: [], returns: [] }, { name: "tryGrowByReslice", args: [{ name: "n", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "grow", args: [{ name: "n", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Grow", args: [{ name: "n", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [] }, { name: "Write", args: [{ name: "p", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "WriteString", args: [{ name: "s", type: { kind: $.TypeKind.Basic, name: "string" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadFrom", args: [{ name: "r", type: "Reader" }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "WriteTo", args: [{ name: "w", type: "Writer" }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "WriteByte", args: [{ name: "c", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "WriteRune", args: [{ name: "r", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Read", args: [{ name: "p", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Next", args: [{ name: "n", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }] }, { name: "ReadByte", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadRune", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "UnreadRune", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "UnreadByte", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadBytes", args: [{ name: "delim", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "readSlice", args: [{ name: "delim", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadString", args: [{ name: "delim", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }], Buffer, diff --git a/gs/bytes/reader.gs.ts b/gs/bytes/reader.gs.ts index 873769d64..5ea2acae0 100644 --- a/gs/bytes/reader.gs.ts +++ b/gs/bytes/reader.gs.ts @@ -193,7 +193,7 @@ export class Reader { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Reader', + 'bytes.Reader', new Reader(), [{ name: "Len", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Size", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }] }, { name: "Read", args: [{ name: "b", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadAt", args: [{ name: "b", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }, { name: "off", type: { kind: $.TypeKind.Basic, name: "int64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadByte", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "UnreadByte", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "ReadRune", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Basic, name: "number" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "UnreadRune", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Seek", args: [{ name: "offset", type: { kind: $.TypeKind.Basic, name: "int64" } }, { name: "whence", type: { kind: $.TypeKind.Basic, name: "number" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "WriteTo", args: [{ name: "w", type: "Writer" }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Reset", args: [{ name: "b", type: { kind: $.TypeKind.Slice, elemType: { kind: $.TypeKind.Basic, name: "number" } } }], returns: [] }], Reader, diff --git a/gs/github.com/pkg/errors/errors.ts b/gs/github.com/pkg/errors/errors.ts index c013cc4eb..40a22260e 100644 --- a/gs/github.com/pkg/errors/errors.ts +++ b/gs/github.com/pkg/errors/errors.ts @@ -66,7 +66,7 @@ class fundamental { } static __typeInfo = $.registerStructType( - 'fundamental', + 'errors.fundamental', new fundamental(), [ { @@ -137,7 +137,7 @@ class withStack { } static __typeInfo = $.registerStructType( - 'withStack', + 'errors.withStack', new withStack(), [ { @@ -289,7 +289,7 @@ class withMessage { } static __typeInfo = $.registerStructType( - 'withMessage', + 'errors.withMessage', new withMessage(), [ { diff --git a/gs/io/fs/fs.ts b/gs/io/fs/fs.ts index b027b87fa..186e1772d 100644 --- a/gs/io/fs/fs.ts +++ b/gs/io/fs/fs.ts @@ -567,7 +567,7 @@ export class PathError { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'PathError', + 'fs.PathError', new PathError(), [ { diff --git a/gs/io/fs/readdir.ts b/gs/io/fs/readdir.ts index 30197f9ed..2e2a18a21 100644 --- a/gs/io/fs/readdir.ts +++ b/gs/io/fs/readdir.ts @@ -148,7 +148,7 @@ class dirInfo { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'dirInfo', + 'fs.dirInfo', new dirInfo(), [ { diff --git a/gs/io/fs/sub.ts b/gs/io/fs/sub.ts index 349548a8f..46696d86c 100644 --- a/gs/io/fs/sub.ts +++ b/gs/io/fs/sub.ts @@ -120,7 +120,7 @@ class subFS { { let { value: e, ok: ok } = $.typeAssert(err, { kind: $.TypeKind.Pointer, - elemType: 'PathError', + elemType: 'fs.PathError', }) if (ok) { { @@ -222,7 +222,7 @@ class subFS { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'subFS', + 'fs.subFS', new subFS(), [ { diff --git a/gs/os/dir_unix.gs.ts b/gs/os/dir_unix.gs.ts index 91fa17925..e69fa38c7 100644 --- a/gs/os/dir_unix.gs.ts +++ b/gs/os/dir_unix.gs.ts @@ -58,7 +58,7 @@ class dirInfo { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'dirInfo', + 'os.dirInfo', new dirInfo(), [{ name: "close", args: [], returns: [] }], dirInfo, diff --git a/gs/os/error.gs.ts b/gs/os/error.gs.ts index 2296f7f3c..4c909f10f 100644 --- a/gs/os/error.gs.ts +++ b/gs/os/error.gs.ts @@ -102,7 +102,7 @@ export class SyscallError { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'SyscallError', + 'os.SyscallError', new SyscallError(), [{ name: "Error", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "Unwrap", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Timeout", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }], SyscallError, diff --git a/gs/os/exec.gs.ts b/gs/os/exec.gs.ts index 0ca2a0ef3..966841e6f 100644 --- a/gs/os/exec.gs.ts +++ b/gs/os/exec.gs.ts @@ -40,12 +40,12 @@ export class Process { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Process', + 'os.Process', new Process(), [ { name: "Release", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Kill", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, - { name: "Wait", args: [], returns: [{ type: { kind: $.TypeKind.Pointer, elemType: "ProcessState" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, + { name: "Wait", args: [], returns: [{ type: { kind: $.TypeKind.Pointer, elemType: "os.ProcessState" } }, { type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }, { name: "Signal", args: [{ name: "sig", type: "Signal" }], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] } ], Process, @@ -81,7 +81,7 @@ export class ProcAttr { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'ProcAttr', + 'os.ProcAttr', new ProcAttr(), [], ProcAttr, @@ -102,7 +102,7 @@ export class ProcessState { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'ProcessState', + 'os.ProcessState', new ProcessState(), [], ProcessState, diff --git a/gs/os/exec_posix.gs.ts b/gs/os/exec_posix.gs.ts index 17f61c3a7..02b571813 100644 --- a/gs/os/exec_posix.gs.ts +++ b/gs/os/exec_posix.gs.ts @@ -62,7 +62,7 @@ export class ProcessState { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'ProcessState', + 'os.ProcessState', new ProcessState(), [ { name: "UserTime", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "any" } }] }, diff --git a/gs/os/root_js.gs.ts b/gs/os/root_js.gs.ts index ecfeed725..2f669efe7 100644 --- a/gs/os/root_js.gs.ts +++ b/gs/os/root_js.gs.ts @@ -221,7 +221,7 @@ export class Root { } static __typeInfo = $.registerStructType( - 'Root', + 'os.Root', new Root(), [ { name: "Name", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }, diff --git a/gs/os/types_unix.gs.ts b/gs/os/types_unix.gs.ts index ab77c26f6..c10c70dc5 100644 --- a/gs/os/types_unix.gs.ts +++ b/gs/os/types_unix.gs.ts @@ -67,7 +67,7 @@ class fileStat { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'fileStat', + 'os.fileStat', new fileStat(), [{ name: "Name", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "IsDir", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Size", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "Mode", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "number" } }] }, { name: "ModTime", args: [], returns: [{ type: "Time" }] }, { name: "Sys", args: [], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }], fileStat, diff --git a/gs/path/path.ts b/gs/path/path.ts index b0a6cc47c..b9357cbd7 100644 --- a/gs/path/path.ts +++ b/gs/path/path.ts @@ -67,7 +67,7 @@ class lazybuf { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'lazybuf', + 'path.lazybuf', new lazybuf(), [ { diff --git a/gs/strconv/atoi.gs.ts b/gs/strconv/atoi.gs.ts index 2f9a679b2..75b497c94 100644 --- a/gs/strconv/atoi.gs.ts +++ b/gs/strconv/atoi.gs.ts @@ -43,7 +43,7 @@ export class NumError { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'NumError', + 'strconv.NumError', new NumError(), [{ name: "Error", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "string" } }] }, { name: "Unwrap", args: [], returns: [{ type: { kind: $.TypeKind.Interface, name: 'GoError', methods: [{ name: 'Error', args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }] }] } }] }], NumError, diff --git a/gs/strings/builder.ts b/gs/strings/builder.ts index 1c48d7b1f..44a06fc5c 100644 --- a/gs/strings/builder.ts +++ b/gs/strings/builder.ts @@ -106,7 +106,7 @@ export class Builder { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Builder', + 'strings.Builder', new Builder(), [ { diff --git a/gs/strings/reader.ts b/gs/strings/reader.ts index 4c2c88a6c..3e2bdc7b7 100644 --- a/gs/strings/reader.ts +++ b/gs/strings/reader.ts @@ -195,7 +195,7 @@ export class Reader { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Reader', + 'strings.Reader', new Reader(), [ { diff --git a/gs/strings/replace.ts b/gs/strings/replace.ts index 44519a6ac..04252318a 100644 --- a/gs/strings/replace.ts +++ b/gs/strings/replace.ts @@ -146,7 +146,7 @@ export class Replacer { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Replacer', + 'strings.Replacer', new Replacer(), [ { name: 'buildOnce', args: [], returns: [] }, diff --git a/gs/sync/atomic/type.gs.ts b/gs/sync/atomic/type.gs.ts index e91c90acc..bde0b0ed1 100644 --- a/gs/sync/atomic/type.gs.ts +++ b/gs/sync/atomic/type.gs.ts @@ -45,7 +45,7 @@ export class Bool { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Bool', + 'atomic.Bool', new Bool(), [{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Basic, name: "boolean" } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Basic, name: "boolean" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Basic, name: "boolean" } }, { name: "new", type: { kind: $.TypeKind.Basic, name: "boolean" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }], Bool, @@ -107,7 +107,7 @@ export class Pointer { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Pointer', + 'atomic.Pointer', new Pointer(), [{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Pointer, elemType: { kind: $.TypeKind.Interface, methods: [] } } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Pointer, elemType: { kind: $.TypeKind.Interface, methods: [] } } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Pointer, elemType: { kind: $.TypeKind.Interface, methods: [] } } }], returns: [{ type: { kind: $.TypeKind.Pointer, elemType: { kind: $.TypeKind.Interface, methods: [] } } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Pointer, elemType: { kind: $.TypeKind.Interface, methods: [] } } }, { name: "new", type: { kind: $.TypeKind.Pointer, elemType: { kind: $.TypeKind.Interface, methods: [] } } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }], Pointer, @@ -442,7 +442,7 @@ export class Uintptr { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Uintptr', + 'atomic.Uintptr', new Uintptr(), [{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "uintptr" } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Basic, name: "uintptr" } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Basic, name: "uintptr" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uintptr" } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Basic, name: "uintptr" } }, { name: "new", type: { kind: $.TypeKind.Basic, name: "uintptr" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Add", args: [{ name: "delta", type: { kind: $.TypeKind.Basic, name: "uintptr" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uintptr" } }] }, { name: "And", args: [{ name: "mask", type: { kind: $.TypeKind.Basic, name: "uintptr" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uintptr" } }] }, { name: "Or", args: [{ name: "mask", type: { kind: $.TypeKind.Basic, name: "uintptr" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uintptr" } }] }], Uintptr, @@ -471,7 +471,7 @@ class noCopy { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'noCopy', + 'atomic.noCopy', new noCopy(), [{ name: "Lock", args: [], returns: [] }, { name: "Unlock", args: [], returns: [] }], noCopy, diff --git a/gs/sync/atomic/value.gs.ts b/gs/sync/atomic/value.gs.ts index c6f70b9af..b25ce0f4e 100644 --- a/gs/sync/atomic/value.gs.ts +++ b/gs/sync/atomic/value.gs.ts @@ -79,7 +79,7 @@ export class Value { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'Value', + 'atomic.Value', new Value(), [{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Interface, methods: [] } }, { name: "new", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }], Value, @@ -106,7 +106,7 @@ class efaceWords { // Register this type with the runtime type system static __typeInfo = $.registerStructType( - 'efaceWords', + 'atomic.efaceWords', new efaceWords(), [], efaceWords, diff --git a/tests/tests/reflect_override_method_sets/expected.log b/tests/tests/reflect_override_method_sets/expected.log index de1fbde9a..6d2c5eef2 100644 --- a/tests/tests/reflect_override_method_sets/expected.log +++ b/tests/tests/reflect_override_method_sets/expected.log @@ -2,3 +2,6 @@ readfile param true time Format true 2 string time pointer methods 47 embed FS true true +methods *strings.Builder true true +methods *bytes.Buffer true true +methods *strings.Reader true true diff --git a/tests/tests/reflect_override_method_sets/reflect_override_method_sets.go b/tests/tests/reflect_override_method_sets/reflect_override_method_sets.go index 74dc40bbb..73e5dcff5 100644 --- a/tests/tests/reflect_override_method_sets/reflect_override_method_sets.go +++ b/tests/tests/reflect_override_method_sets/reflect_override_method_sets.go @@ -1,10 +1,12 @@ package main import ( + "bytes" "embed" "fmt" "io/fs" "reflect" + "strings" "time" ) @@ -21,4 +23,11 @@ func main() { var efs embed.FS fsType := reflect.TypeOf((*fs.FS)(nil)).Elem() fmt.Println("embed FS", reflect.TypeOf(efs).Implements(fsType), reflect.TypeOf(&efs).Implements(fsType)) + + // Pointers to override struct types, reached only by reflection, have + // the methods of their Go types. + for _, v := range []reflect.Value{reflect.ValueOf((*strings.Builder)(nil)), reflect.ValueOf((*bytes.Buffer)(nil)), reflect.ValueOf((*strings.Reader)(nil))} { + _, ok := v.Type().MethodByName("Len") + fmt.Println("methods", v.Type(), v.Type().NumMethod() > 0, ok) + } } diff --git a/tests/tests/reflect_override_method_sets/reflect_override_method_sets.gs.ts b/tests/tests/reflect_override_method_sets/reflect_override_method_sets.gs.ts index 32658a13e..1d529e7ea 100644 --- a/tests/tests/reflect_override_method_sets/reflect_override_method_sets.gs.ts +++ b/tests/tests/reflect_override_method_sets/reflect_override_method_sets.gs.ts @@ -2,12 +2,16 @@ // Updated when compliance tests are re-run, DO NOT EDIT! import * as $ from "@goscript/builtin/index.js" +import * as bytes from "@goscript/bytes/index.js" import * as embed from "@goscript/embed/index.js" import * as fmt from "@goscript/fmt/index.js" import * as fs from "@goscript/io/fs/index.js" import * as reflect from "@goscript/reflect/index.js" +import * as strings from "@goscript/strings/index.js" import * as time from "@goscript/time/index.js" +import "@goscript/bytes/index.js" import "@goscript/io/fs/index.js" +import "@goscript/strings/index.js" export async function main(): globalThis.Promise { // The fs.FS parameter of fs.ReadFile, registered by hand, takes an @@ -22,6 +26,14 @@ export async function main(): globalThis.Promise { let efs = $.varRef($.markAsStructValue(new embed.FS())) let fsType = (__goscriptAwait = $.pointerValue>(reflect.TypeOf($.interfaceValue(null, "*fs.FS", __goscriptStatic6()))).Elem(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) fmt.Println("embed FS", (__goscriptAwait = $.pointerValue>(reflect.TypeOf($.structInterfaceValue($.markAsStructValue($.cloneStructValue(efs.value)), "embed.FS", __goscriptStatic0()))).Implements($.pointerValueOrNil(fsType)!), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait), (__goscriptAwait = $.pointerValue>(reflect.TypeOf($.interfaceValue(efs, "*embed.FS", __goscriptStatic7()))).Implements($.pointerValueOrNil(fsType)!), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait)) + + // Pointers to override struct types, reached only by reflection, have + // the methods of their Go types. + for (let __goscriptRangeTarget0 = $.arrayToSlice([$.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(null, "*strings.Builder", __goscriptStatic8())))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(null, "*bytes.Buffer", __goscriptStatic9())))), $.markAsStructValue($.cloneStructValue(reflect.ValueOf($.interfaceValue(null, "*strings.Reader", __goscriptStatic10()))))]), __goscriptRangeWindow0 = $.sliceRange(__goscriptRangeTarget0), __rangeIndex = 0; __rangeIndex < __goscriptRangeWindow0.length; __rangeIndex++) { + let v = $.markAsStructValue($.cloneStructValue((__goscriptRangeWindow0.backing[__goscriptRangeWindow0.offset + __rangeIndex] as reflect.Value))) + let [, __goscriptShadow0] = await $.pointerValue>($.markAsStructValue($.cloneStructValue(v)).Type()).MethodByName("Len") + fmt.Println("methods", ($.markAsStructValue($.cloneStructValue(v)).Type() as any), (__goscriptAwait = $.pointerValue>($.markAsStructValue($.cloneStructValue(v)).Type()).NumMethod(), __goscriptAwait instanceof Promise ? await __goscriptAwait : __goscriptAwait) > 0, __goscriptShadow0) + } } var __goscriptStatic0$value: any @@ -64,6 +76,21 @@ function __goscriptStatic7(): any { return __goscriptStatic7$value ??= ($.overrideTypeMethods(/* @__PURE__ */ $.pointerType("embed.FS"), "embed.FS", () => [$.methodSignature("Open", [["name", /* @__PURE__ */ $.basicType("string")]], ["fs.File", "error"]), $.methodSignature("ReadDir", [["name", /* @__PURE__ */ $.basicType("string")]], [/* @__PURE__ */ $.sliceType("fs.DirEntry"), "error"]), $.methodSignature("ReadFile", [["name", /* @__PURE__ */ $.basicType("string")]], [/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8")), "error"])])) } +var __goscriptStatic8$value: any +function __goscriptStatic8(): any { + return __goscriptStatic8$value ??= ($.overrideTypeMethods(/* @__PURE__ */ $.pointerType("strings.Builder"), "strings.Builder", () => [$.methodSignature("Cap", [], [/* @__PURE__ */ $.basicType("int")], true), $.methodSignature("Grow", [["n", /* @__PURE__ */ $.basicType("int")]], [], true), $.methodSignature("Len", [], [/* @__PURE__ */ $.basicType("int")], true), $.methodSignature("Reset", [], [], true), $.methodSignature("String", [], [/* @__PURE__ */ $.basicType("string")], true), $.methodSignature("Write", [["p", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))]], [/* @__PURE__ */ $.basicType("int"), "error"], true), $.methodSignature("WriteByte", [["c", /* @__PURE__ */ $.basicType("uint8")]], ["error"], true), $.methodSignature("WriteRune", [["r", /* @__PURE__ */ $.basicType("int32")]], [/* @__PURE__ */ $.basicType("int"), "error"], true), $.methodSignature("WriteString", [["s", /* @__PURE__ */ $.basicType("string")]], [/* @__PURE__ */ $.basicType("int"), "error"], true)])) +} + +var __goscriptStatic9$value: any +function __goscriptStatic9(): any { + return __goscriptStatic9$value ??= ($.overrideTypeMethods(/* @__PURE__ */ $.pointerType("bytes.Buffer"), "bytes.Buffer", () => [$.methodSignature("Available", [], [/* @__PURE__ */ $.basicType("int")], true), $.methodSignature("AvailableBuffer", [], [/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))], true), $.methodSignature("Bytes", [], [/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))], true), $.methodSignature("Cap", [], [/* @__PURE__ */ $.basicType("int")], true), $.methodSignature("Grow", [["n", /* @__PURE__ */ $.basicType("int")]], [], true), $.methodSignature("Len", [], [/* @__PURE__ */ $.basicType("int")], true), $.methodSignature("Next", [["n", /* @__PURE__ */ $.basicType("int")]], [/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))], true), $.methodSignature("Peek", [["n", /* @__PURE__ */ $.basicType("int")]], [/* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8")), "error"], true), $.methodSignature("Read", [["p", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))]], [["n", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("ReadByte", [], [/* @__PURE__ */ $.basicType("uint8"), "error"], true), $.methodSignature("ReadBytes", [["delim", /* @__PURE__ */ $.basicType("uint8")]], [["line", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))], ["err", "error"]], true), $.methodSignature("ReadFrom", [["r", "io.Reader"]], [["n", /* @__PURE__ */ $.basicType("int64")], ["err", "error"]], true), $.methodSignature("ReadRune", [], [["r", /* @__PURE__ */ $.basicType("int32")], ["size", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("ReadString", [["delim", /* @__PURE__ */ $.basicType("uint8")]], [["line", /* @__PURE__ */ $.basicType("string")], ["err", "error"]], true), $.methodSignature("Reset", [], [], true), $.methodSignature("String", [], [/* @__PURE__ */ $.basicType("string")], true), $.methodSignature("Truncate", [["n", /* @__PURE__ */ $.basicType("int")]], [], true), $.methodSignature("UnreadByte", [], ["error"], true), $.methodSignature("UnreadRune", [], ["error"], true), $.methodSignature("Write", [["p", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))]], [["n", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("WriteByte", [["c", /* @__PURE__ */ $.basicType("uint8")]], ["error"], true), $.methodSignature("WriteRune", [["r", /* @__PURE__ */ $.basicType("int32")]], [["n", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("WriteString", [["s", /* @__PURE__ */ $.basicType("string")]], [["n", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("WriteTo", [["w", "io.Writer"]], [["n", /* @__PURE__ */ $.basicType("int64")], ["err", "error"]], true)])) +} + +var __goscriptStatic10$value: any +function __goscriptStatic10(): any { + return __goscriptStatic10$value ??= ($.overrideTypeMethods(/* @__PURE__ */ $.pointerType("strings.Reader"), "strings.Reader", () => [$.methodSignature("Len", [], [/* @__PURE__ */ $.basicType("int")], true), $.methodSignature("Read", [["b", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))]], [["n", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("ReadAt", [["b", /* @__PURE__ */ $.sliceType(/* @__PURE__ */ $.basicType("uint8"))], ["off", /* @__PURE__ */ $.basicType("int64")]], [["n", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("ReadByte", [], [/* @__PURE__ */ $.basicType("uint8"), "error"], true), $.methodSignature("ReadRune", [], [["ch", /* @__PURE__ */ $.basicType("int32")], ["size", /* @__PURE__ */ $.basicType("int")], ["err", "error"]], true), $.methodSignature("Reset", [["s", /* @__PURE__ */ $.basicType("string")]], [], true), $.methodSignature("Seek", [["offset", /* @__PURE__ */ $.basicType("int64")], ["whence", /* @__PURE__ */ $.basicType("int")]], [/* @__PURE__ */ $.basicType("int64"), "error"], true), $.methodSignature("Size", [], [/* @__PURE__ */ $.basicType("int64")], true), $.methodSignature("UnreadByte", [], ["error"], true), $.methodSignature("UnreadRune", [], ["error"], true), $.methodSignature("WriteTo", [["w", "io.Writer"]], [["n", /* @__PURE__ */ $.basicType("int64")], ["err", "error"]], true)])) +} + var __goscriptAwait: any if ($.isMainScript(import.meta)) {