Skip to content

Conversation

@fruno-bulax
Copy link
Contributor

@fruno-bulax fruno-bulax commented Dec 5, 2025

Closes #5184.

The implementation of this did not go as expected.

In short, we naturally already construct the missing patterns in a very intuitive order.
However, there can be duplicate patterns involving wildcards, which is probably why the strings were put in a set, losing that order. To then regain a stable order, the patterns were sorted lexicographically.

This PR maintains the original order and keeps the set only to prune duplicates.

As you can see from the updated snapshots, this has the nice side effect of also ordering list patterns by the number of elements being matched on.

@fruno-bulax fruno-bulax mentioned this pull request Dec 5, 2025
@fruno-bulax fruno-bulax changed the title ✨ Order type variants by definition index ✨ Improve ordering of missing patterns Dec 5, 2025
@giacomocavalieri
Copy link
Member

Oh wow now list patterns, bools and results are nicely ordered. Love this 💖

Just left a comment for some clarification

@fruno-bulax fruno-bulax force-pushed the order-missing-patterns branch 2 times, most recently from 74d6b4b to 77e0b65 Compare December 5, 2025 21:52
@fruno-bulax fruno-bulax force-pushed the order-missing-patterns branch from 77e0b65 to 29f8a11 Compare December 6, 2025 23:53
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Wonderful! It's the little things that make big differences to how it feels to write Gleam :)

Thank you!!

[_, _] -> todo
[_, _, _] -> todo
[_, _, _, _] -> todo
[_, _, _, _, _, ..] -> todo
Copy link
Member

Choose a reason for hiding this comment

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

this is so pretty now

@lpil lpil merged commit ba32828 into gleam-lang:main Dec 8, 2025
12 checks passed
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.

Make "Add missing patterns" code action insert variants in order of definition.

3 participants