Skip to content

interp: panic "reading values of different sizes" on short-receiver method call in init #5642

Description

@soypat
package main

// Reproducer: tinygo interp panics with "comparing values of different size"
// when a package-level initializer makes an interface method call on a
// receiver whose underlying type is narrower than a pointer.
//
// The $invoke thunk widens the receiver to pointer size via ptrtoint, but the
// method body compares it against a constant of the declared width, so
// interp's rawValue.equal gets a 4-byte lhs and a 1-byte rhs.
//
//	tinygo build -target=pico -o=/dev/null .

type handle interface{ id() int }

type narrow uint8 // uint16 also fails; uintptr-width does not

func (h narrow) id() int {
	if h == 1 {
		return 10
	}
	return 0
}

var h handle = narrow(1)

var n = h.id() // evaluated by interp at compile time

func main() { println(n) }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions