We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The following example causes the crash for library
package main import ( "fmt" "github.com/fogfish/golem/optics" ) type Story struct { Text *string } func main() { l := optics.ForProduct1[*Story, *string]() s := &Story{} x := "xxx" l.Put(&s, &x) fmt.Printf("==> %+v\n", s) fmt.Printf("==> %v\n", s.Text) fmt.Printf("==> %s\n", *s.Text) // <= crash here }
The reason is lens internals. It assume S is pure structure. As fix, the lens needs to know a metadata about S type.
func (lens *lens[S, A]) Put(s *S, a A) *S { *(*A)(unsafe.Pointer(uintptr(unsafe.Pointer(s)) + lens.Offset + lens.RootOffs)) = a return s } func (lens *lens[S, A]) Get(s *S) A { return *(*A)(unsafe.Pointer(uintptr(unsafe.Pointer(s)) + lens.Offset + lens.RootOffs)) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The following example causes the crash for library
The reason is lens internals. It assume S is pure structure. As fix, the lens needs to know a metadata about S type.
The text was updated successfully, but these errors were encountered: