gf icon indicating copy to clipboard operation
gf copied to clipboard

util/gconv: when Scan **Struct to **Struct, if dstValue is nil, will return reflect: reflect.Value.Set using unaddressable value

Open StrangeYear opened this issue 1 month ago • 2 comments

Go version

1.25.4

GoFrame version

2.9.4

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

package gconv

import (
	"fmt"
	"testing"
)

type User struct {
	Id int64
}

func TestScan(t *testing.T) {
	var user *User
	cacheValue := &User{Id: 1}
	err := Scan(&cacheValue, &user)
	if err != nil {
		t.Error(err)
	}
	fmt.Printf("user:%+v\n", user)
}

What did you see happen?

=== RUN TestScan gconv_scan_test.go:17: reflect: reflect.Value.Set using unaddressable value user: --- FAIL: TestScan (0.00s)

What did you expect to see?

when in goframe version 2.6.3, it is ok.

StrangeYear avatar Nov 09 '25 06:11 StrangeYear

The right thing to do is this

gconv.Scan(cacheValue, &user)

LanceAdd avatar Nov 14 '25 02:11 LanceAdd

The right thing to do is this

gconv.Scan(cacheValue, &user)

It can run normally in versions earlier than 2.6.3

StrangeYear avatar Dec 05 '25 02:12 StrangeYear