Skip to content

reflect: closure calls via reflect.Value.Call crash on ctxreg targets #1615

@MeteorsLiu

Description

@MeteorsLiu
  package main

  import (
        "fmt"
        "reflect"
  )

  func main() {
        x := 10
        add := func(n int) int {
                return x + n
        }

        fmt.Printf("Direct: %d\n", add(5)) // Works: 15

        v := reflect.ValueOf(add)
        r := v.Call([]reflect.Value{reflect.ValueOf(5)}) // Crash
        fmt.Printf("Reflect: %d\n", r[0].Int())
  }

Expected Behavior

Output:
Direct: 15
Reflect: 15

Actual Behavior

Direct: 15
panic: runtime error: invalid memory address or nil pointer dereference
[... ffi_call_SYSV ...]

Related PR: #1599

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