Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/StructTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ mappings will be applied, and the function will be passed the Julia field name.
end
end
)
if !f_applied && haskey(defaults(T), nm)
setfield!(x, nm, defaults(T)[nm])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep unknown and excluded fields untouched

This fallback runs precisely when nm did not match an allowed field. For a mutable type with only value::Int and defaults(T) = (value=10, extra=20), applyfield!(f, x, :extra) now throws because extra is not a field; it previously returned false. constructfrom also fails because it merges defaults before calling this dispatcher. For an excluded value with constructor value 42 and default 10, this block overwrites the value with 10 while returning false. The documented API skips unknown/excluded fields and returns whether the callback ran. Please remove the invalid block from applyfield without adding it here, and cover both cases.

AI disclosure: This work was prepared with assistance from OpenAI Codex.

end
return f_applied
end

Expand Down Expand Up @@ -890,9 +893,6 @@ mappings will be applied, and the function will be passed the Julia field name.
end
end
)
if !f_applied && haskey(defaults(T), nm)
setfield!(x, nm, defaults(T)[nm])
end
return f_applied
end

Expand Down