From 77644375ce95b6e8268e06996f2031ef6d03f2a2 Mon Sep 17 00:00:00 2001 From: Team Humaki Date: Thu, 17 Sep 2026 01:51:40 -0700 Subject: [PATCH] struct: keep reflecting fields after StructReflector ReflectFrom returned as soon as a field implemented StructReflector, so later fields were dropped. Call the custom reflector then continue. Fixes #364. --- struct.go | 5 ++++- struct_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/struct.go b/struct.go index 819a6e5..cf71d2b 100644 --- a/struct.go +++ b/struct.go @@ -598,7 +598,10 @@ func (s *Section) reflectFrom(val reflect.Value) error { } if r, ok := field.Interface().(StructReflector); ok { - return r.ReflectINIStruct(s.f) + if err := r.ReflectINIStruct(s.f); err != nil { + return err + } + continue } fieldName := s.parseFieldName(tpField.Name, rawName) diff --git a/struct_test.go b/struct_test.go index ad6ad04..05c53b5 100644 --- a/struct_test.go +++ b/struct_test.go @@ -871,12 +871,17 @@ func (es Employers) ReflectINIStruct(f *File) error { return nil } +type Address struct { + Line1, Line2 string +} + // Inspired by https://github.com/go-ini/ini/issues/199 func Test_StructReflector(t *testing.T) { t.Run("reflect with StructReflector interface", func(t *testing.T) { p := &struct { FirstName string Employer Employers + Address Address }{ FirstName: "Andrew", Employer: []*Employer{ @@ -889,6 +894,10 @@ func Test_StructReflector(t *testing.T) { Title: "Consultant Engineer", }, }, + Address: Address{ + Line1: "123 Ini Drive", + Line2: "Section 1", + }, } f := Empty() @@ -905,6 +914,10 @@ Title = Staff II Engineer [Employer "EMC"] Title = Consultant Engineer + +[Address] +Line1 = 123 Ini Drive +Line2 = Section 1 `, buf.String(), )