@@ -126,7 +126,7 @@ fn setStructFieldByName(
126126 const is_optional = @typeInfo (field .type ) == .optional ;
127127 const target_type = if (is_optional ) @typeInfo (field .type ).optional .child else field .type ;
128128
129- if (is_optional and ( value . len == 0 or eqlIgnoreCase (value , "null" ) )) {
129+ if (is_optional and eqlIgnoreCase (value , "null" )) {
130130 @field (instance , field .name ) = null ;
131131 return ;
132132 }
@@ -187,13 +187,12 @@ test "Set struct Field by Name" {
187187 try setStructFieldByName (EnvArgs , & args , "name" , "Me" , alloc );
188188 try setStructFieldByName (EnvArgs , & args , "male" , "false" , alloc );
189189 try setStructFieldByName (EnvArgs , & args , "age" , "420" , alloc );
190- try setStructFieldByName (EnvArgs , & args , "max_lifetime" , "" , alloc ); // should be null
191190
192191 try std .testing .expectEqualSlices (u8 , "Me" , args .name );
193192 try std .testing .expectEqual (420 , args .age );
194193 try std .testing .expectEqual (false , args .male );
195194 try std .testing .expectEqual (3.0 , args .pi );
196- try std .testing .expectEqual (null , args .max_lifetime );
195+ try std .testing .expectEqual (50 , args .max_lifetime .? );
197196 try std .testing .expectEqualSlices (u8 , "yoyo" , args .nick_name );
198197}
199198
0 commit comments