Conversation
hoe-jo
commented
Mar 3, 2026
- Add Implementation
- Add System Tests
- Add Documentation
- Update LRM
- Add Implementation - Add System Tests - Add Documentation - Update LRM
| #### union_partial_field_access | ||
|
|
||
| Accessing a field on a union type that does not exist in all member | ||
| types is allowed but may return `null` at run-time. The linter warns |
There was a problem hiding this comment.
Small formatting issue: there are two spaces in
“run-time. The linter warns...”
| types may not appear in a union type.''' | ||
| } | ||
|
|
||
| Static_Semantics Union_Type_No_Field_Access { |
There was a problem hiding this comment.
Name is a bit confusing. Rule name says “No_Field_Access”, but text says field access is allowed in some cases.
| # lobster-trace: LRM.Valid_Index_Prefixes | ||
| self.mh.error(n_name.location, | ||
| "expression '%s' has type %s, " | ||
| "which is not a tuple or record" % |
There was a problem hiding this comment.
Suggestion: change to "which is not a tuple, record, or union".
|
|
||
| # We can now perform the access on the record value | ||
| field_map = prefix_typ.get_field_map() | ||
| union_id = "_".join(t.name for t in prefix_typ.types) |
There was a problem hiding this comment.
This needs one more system test.
union SMT names are built only from short type names.
If two packages have same type names, generated SMT names can clash.
Please add a cross-package test with same short type names to make sure no collision happens.
| # We can compary anything to null (including itself) | ||
| pass | ||
| elif isinstance(self.n_lhs.typ, Union_Type) or \ | ||
| isinstance(self.n_rhs.typ, Union_Type): |
There was a problem hiding this comment.
Should equality between a union-typed reference and an unrelated record type be allowed? For example, if we have parent [A, B] and other C, should parent == other be valid, or should it be a type error because C is not compatible with [A, B]? If this is intentional, it would help to add a system test to lock that behavior.