Skip to content

panic: reflect.Value.Interface: cannot return value obtained from unexported field or method #14

Description

@jazzy-crane

I get a panic running the following script:

package main

import (
	"fmt"

	"github.com/starlight-go/starlight"
)

type foo struct {
	HelloWorld string
}

type bar struct {
	Exported   *foo
	unexported *foo
}

func main() {
	testdata := &bar{
		Exported:   &foo{"Hello World!"},
		unexported: &foo{"hELLO wORLD!"},
	}

	globals := map[string]interface{}{
		"Println":  fmt.Println,
		"testdata": testdata,
	}

	_, err := starlight.Eval([]byte(`
Println(testdata.Exported.HelloWorld)
Println(testdata.unexported.HelloWorld)
Println(testdata.Exported)
Println(testdata.unexported)
`), globals, nil)
	if err != nil {
		fmt.Println("Error executing script;", err)
	}
}

It is the final line in the script that causes the panic (Println(testdata.unexported))

C:\MyGo\src\TEST\starlighttest>go build && starlighttest.exe
Hello World!
hELLO wORLD!
&{Hello World!}
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method

goroutine 1 [running]:
reflect.valueInterface(0x577960, 0xc00004e218, 0x1b6, 0x1, 0x10, 0x58b580)
        C:/Go/src/reflect/value.go:959 +0x1c5
reflect.Value.Interface(0x577960, 0xc00004e218, 0x1b6, 0x0, 0x703dc0)
        C:/Go/src/reflect/value.go:948 +0x4b
github.com/starlight-go/starlight/convert.FromValue(0x5e6340, 0xc0000547c0, 0x1, 0xc00004e430)
        C:/MyGo/src/github.com/starlight-go/starlight/convert/conv.go:109 +0x1cb
github.com/starlight-go/starlight/convert.FromTuple(0xc00004e420, 0x1, 0x1, 0x5e7060, 0x58a200, 0x8)
        C:/MyGo/src/github.com/starlight-go/starlight/convert/conv.go:152 +0xaf
github.com/starlight-go/starlight/convert.makeVariadicStarFn.func1(0xc00006e9f0, 0xc00006e9c0, 0xc00004e420, 0x1, 0x1, 0x0, 0x0, 0x0, 0x50, 0x5a4020, ...)
        C:/MyGo/src/github.com/starlight-go/starlight/convert/conv.go:340 +0xcb
go.starlark.net/starlark.(*Builtin).CallInternal(0xc00006e9c0, 0xc00006e9f0, 0xc00004e420, 0x1, 0x1, 0x0, 0x0, 0x0, 0x703dc0, 0x411053, ...)
        C:/MyGo/src/go.starlark.net/starlark/value.go:632 +0x92
go.starlark.net/starlark.Call(0xc00006e9f0, 0x5e6380, 0xc00006e9c0, 0xc00004e420, 0x1, 0x1, 0x0, 0x0, 0x0, 0x5e6540, ...)
        C:/MyGo/src/go.starlark.net/starlark/eval.go:991 +0x14e
go.starlark.net/starlark.(*Function).CallInternal(0xc0000ae000, 0xc00006e9f0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, ...)
        C:/MyGo/src/go.starlark.net/starlark/interp.go:283 +0x3da3
go.starlark.net/starlark.Call(0xc00006e9f0, 0x5e6400, 0xc0000ae000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000082020, ...)
        C:/MyGo/src/go.starlark.net/starlark/eval.go:991 +0x14e
go.starlark.net/starlark.(*Program).Init(0xc000082020, 0xc00006e9f0, 0xc00006e990, 0xc000054460, 0xc00004e240, 0xc0000a4060)
        C:/MyGo/src/go.starlark.net/starlark/eval.go:339 +0xa1
go.starlark.net/starlark.ExecFile(0xc00006e9f0, 0x5b92d1, 0x8, 0x57ce00, 0xc000054460, 0xc00006e990, 0x20, 0x57ce00, 0x1)
        C:/MyGo/src/go.starlark.net/starlark/eval.go:268 +0xf4
github.com/starlight-go/starlight.Eval(0x57ce00, 0xc000054460, 0xc00007fe48, 0x0, 0x87, 0x90, 0xd0)
        C:/MyGo/src/github.com/starlight-go/starlight/starlight.go:41 +0x161
main.main()
        C:/MyGo/src/TEST/starlighttest/starlighttest.go:29 +0x251

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions