Skip to content

[TRLC]: Implement Union Type#171

Open
hoe-jo wants to merge 1 commit intomainfrom
joho_introduce_union_type
Open

[TRLC]: Implement Union Type#171
hoe-jo wants to merge 1 commit intomainfrom
joho_introduce_union_type

Conversation

@hoe-jo
Copy link
Copy Markdown
Contributor

@hoe-jo hoe-jo commented Mar 3, 2026

  • Add Implementation
  • Add System Tests
  • Add Documentation
  • Update LRM

- Add Implementation
- Add System Tests
- Add Documentation
- Update LRM
@hoe-jo hoe-jo requested a review from a team as a code owner March 3, 2026 14:25
@hoe-jo hoe-jo requested a review from florianschanda March 3, 2026 14:34
#### 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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" %
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants