Closed 13k closed 8 months ago
Currently, declarations of record functions expect identical types if they are already declared in the record. As you realized, you can just use the assignment form for assignments that require subtyping relations. Honestly, I actually like this behavior since this also helps the reader notice that there's something special going on with that record field.
From an OO perspective, it feels like assignments are "you can replace this object's attribute at will" whereas declarations feels like "this is a behavior of the object".
When declaring records as classes, it feels right to use declarations to explicitly define behavior.
All of that is subjective, of course.
It's also probably an uncommon case where an object's field could be a function and something else.
Feel free to close as wontfix if you feel the current behavior is favored.
Thanks for the feedback! I'm closing this as the change is not currently planned, then.
When a record has a field with a union type that could be a function, declaring the field as that function fails.
Test case: