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

cannot detect case when exporting the address of a struct member #27

Open
ljw7630 opened this issue Jul 9, 2024 · 1 comment
Open
Assignees

Comments

@ljw7630
Copy link

ljw7630 commented Jul 9, 2024

package main
import "fmt"

type Transaction struct {
	ID     int
	Status int
}

func main() {
	var txns []Transaction
	for i := 0; i < 10; i++ {
		txns = append(txns, Transaction{ID: i, Status: 0})
	}
	var ptr []*int
	for _, txn := range txns {
		fmt.Printf("Transaction ID: %d, Status addr: %p\n", txn.ID, &(txn.Status))
		ptr = append(ptr, &(txn.Status))
	}
}

running: exportloopref got no error

@kyoh86
Copy link
Owner

kyoh86 commented Jul 13, 2024

@ljw7630 You don't need to wrap txn.Status with braces.
exportloopref cannot find the wrapped pointer.

package main
import "fmt"

type Transaction struct {
	ID     int
	Status int
}

func main() {
	var txns []Transaction
	for i := 0; i < 10; i++ {
		txns = append(txns, Transaction{ID: i, Status: 0})
	}
	var ptr []*int
	for _, txn := range txns {
		fmt.Printf("Transaction ID: %d, Status addr: %p\n", txn.ID, &(txn.Status))
		ptr = append(ptr, &txn.Status)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants