Add openStructOption & structOption#5
Conversation
|
fix the error output of /*
(struct {name = string;}) { addr = "xxx"; }
=>
expected 'anon'-struct, but found:
missing required string field 'name'
unexpected struct field 'addr
(struct {age = string;}) { addr = "xxx"; }
=>
expected 'anon'-struct, but found:
missing required int field 'age'
unexpected struct field 'addr'
either (struct {name = string;}) (struct { age = int; }) { addr = "xxx"; }
=>
expected type 'either<anon, anon>', but value '{
addr = "xxx";
}' is of type 'set'
after |
4568cbb to
cde27c2
Compare
blaggacao
left a comment
There was a problem hiding this comment.
Would an option struct not better pe composed of a strict with option type?
| err = ""; | ||
| }; | ||
| # Function to check if a field should be ignored | ||
| shouldIgnore = n: ignored || hasAttr n def; |
There was a problem hiding this comment.
I fail to grok how hasAttr n def translates to the concept of "should ignore". Could you find a more suitable name?
| in | ||
| if shouldIgnore n | ||
| then | ||
| if hasAttr n def |
There was a problem hiding this comment.
This is somewhat redundant, because it's already checked in one branch of shouldIgnore.
Maybe it's just the naming that confuses me here 😊
Ideally, the redundant branches could be unified.
Edit: for clarity I suggest you do a plain 3-branch case (if else) statement (ignored/hasattr/else)
| => | ||
| { Inputs = { ... }; } | ||
| */ | ||
| structOption = arg: |
There was a problem hiding this comment.
I parse this name as an "option for a struct", but it rather is a "struct with all elements being optional".
The field type must be included within the {...} structAttrs.
If the field type exists within {...} structAttrs
contrast with: