Skip to content

Conversation

@Ph0enixKM
Copy link
Member

Closes #442

@Ph0enixKM Ph0enixKM requested review from Copilot and lens0021 December 8, 2025 15:04
@Ph0enixKM Ph0enixKM linked an issue Dec 8, 2025 that may be closed by this pull request
@Ph0enixKM Ph0enixKM self-assigned this Dec 8, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for union types to the Amber programming language, allowing function parameters and variables to accept multiple types. This enables more flexible type signatures like foo(x: Int | Bool | Text) where a parameter can accept any of the specified types.

Key changes:

  • Added Type::Union(Vec<Type>) variant to represent union types
  • Implemented union type parsing with left-to-right associativity using the | operator
  • Updated type checking logic to handle union type compatibility

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/modules/types.rs Core implementation: adds Union type variant, implements parsing logic with try_parse_type and try_parse_simple_type functions, updates type checking with proper subset logic for unions, and adds Display formatting
src/tests/validity/union_types_valid.ab Validity test covering basic union types (Int|Bool|Text), union of arrays ([Int]|[Bool]), and arrays of unions ([Int|Bool])
src/tests/erroring/union_types_mismatch.ab Error test verifying type mismatch detection when passing incompatible types to union-typed parameters
grammar.ebnf Updates TYPE grammar rule to support union syntax with | operator
.gitignore Housekeeping: adds .agent/ directory to ignore list and removes trailing newline

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Mte90 Mte90 self-requested a review December 9, 2025 09:22
@Ph0enixKM Ph0enixKM merged commit 653620c into staging Dec 10, 2025
14 checks passed
@Ph0enixKM Ph0enixKM deleted the 442-feature-union-type branch December 10, 2025 13:02
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.

[Feature] union type

3 participants