Skip to content

Conversation

toqueteos
Copy link
Contributor

When searching for a solution for #40 (now implemented/merged in #41) I stumbled upon the simplify function and I found it weird that it tracked multiple times the same types.

Types are unique so it now only tracks each time once.

There was already a test for this so I've only updated it.

Comment on lines 8 to 10
type Repeated[T string | string | int64 | uint64] struct {
Value T
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a non-literal type as well, as the simplify change only dedupes literals. An eventual change might be to dedupe these as well 🤷

Suggested change
type Repeated[T string | string | int64 | uint64] struct {
Value T
}
type Foo struct{}
type Repeated[T string | string | int64 | uint64 | Foo | Foo] struct {
Value T
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that but Go failed to type-check because it's invalid code. Can't define the same type twice as generic constraint

Copy link
Member

Choose a reason for hiding this comment

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

TIL 👍


func simplifyUnion(union *UnionType) *UnionType {
types := []ExpressionType{}
set := map[string]bool{}
Copy link
Member

Choose a reason for hiding this comment

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

Since the set is only tracking literals, can we rename this? If we eventually add deduping more complex types, I think we will need to come up with some other compare mechanism

Suggested change
set := map[string]bool{}
literalsSet := map[string]bool{}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 8992995

@Emyrk Emyrk merged commit 0e3dfdb into coder:main Jul 29, 2025
1 check passed
@toqueteos toqueteos deleted the feat/simplify-union branch July 29, 2025 16:21
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