Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for methodset existance #4126

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion interp/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,20 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
if err != nil {
return nil, mem, r.errorAt(inst, err)
}
// typecodePtr always point to the numMethod field in the type
// description struct. The methodSet, when present, comes right
// before the numMethod field (the compiler doesn't generate
// method sets for concrete types without methods).
// Considering that the compiler doesn't emit interface type
// asserts for interfaces with no methods (as the always succeed)
// then if the offset is zero, this assert must always fail.
if typecodePtr.offset() == 0 {
locals[inst.localIndex] = literalValue{uint8(0)}
break
}
marco6 marked this conversation as resolved.
Show resolved Hide resolved
typecodePtrOffset, err := typecodePtr.addOffset(-int64(r.pointerSize))
if err != nil {
return nil, mem, r.errorAt(inst, err) // unlikely
return nil, mem, r.errorAt(inst, err)
}
methodSetPtr, err := mem.load(typecodePtrOffset, r.pointerSize).asPointer(r)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions testdata/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,14 @@ func sliceString(s string, start, end int) string {
func sliceSlice(s []int, start, end int) []int {
return s[start:end]
}

type outside struct{}

func init() {
_, _ = any(0).(interface{ DoesNotExist() })
_, _ = any("").(interface{ DoesNotExist() })
_, _ = any(outside{}).(interface{ DoesNotExist() })

type inside struct{}
_, _ = any(inside{}).(interface{ DoesNotExist() })
}