Skip to content

Match element fixes - #13002

Merged
0x6e merged 2 commits into
slint-ui:masterfrom
R-Cramer4:match-fixes
Sep 18, 2026
Merged

0x6e merged 2 commits into
slint-ui:masterfrom
R-Cramer4:match-fixes

Conversation

@R-Cramer4

@R-Cramer4 R-Cramer4 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This pr resolves the rest of the issues in #12680

  • Matching on floats now produces an error
    • It also errors on float to int conversion except in the case of a float like 1.0 or 3.0
  • No more O(N2) operations while checking the cases for duplicates/exhaustiveness
    • This did result in Hash being implemented for EnumerationValue and derived for Unit
  • Added js test blocks for all match statement tests
  • Duration with different units test case was added already
  • Nit about potentially unnecessary use of Option I believe was already addressed

Comment thread internal/compiler/tests/syntax/match_element/float_error.slint
Comment thread internal/compiler/tests/syntax/match_element/float_error.slint
@R-Cramer4 R-Cramer4 changed the title Match statement fixes Match element fixes Aug 24, 2026
Comment thread internal/compiler/passes/resolving.rs
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/tests/syntax/match_element/float_error.slint Outdated
Comment thread internal/compiler/tests/syntax/match_element/float_error.slint
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/tests/syntax/match_element/cast.slint Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/tests/syntax/match_element/cast.slint Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/tests/syntax/match_element/cast.slint
Comment thread internal/compiler/passes/resolving.rs Outdated
@0x6e

0x6e commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Thanks, I think this is ready for a final ok from @ogoffart .

@0x6e
0x6e requested a review from ogoffart September 9, 2026 08:58
@0x6e 0x6e mentioned this pull request Sep 9, 2026
13 tasks

@ogoffart ogoffart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure about this float restriction.
We allow == on float.
matching a float on a 0 is the same as matching it on a 0.0
Also there is no restruction for, say, length which has the same problem.

Comment thread internal/compiler/langtype.rs
Comment thread internal/compiler/tests/syntax/match_element/float_error.slint Outdated
Comment thread internal/compiler/tests/syntax/match_element/float_error.slint Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
Comment thread internal/compiler/passes/resolving.rs Outdated
@0x6e

0x6e commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

The float restriction was based on this. If you think we should allow it, I think it would have to be allowed based on the existing fuzzy comparison in Slint.

We have to consider how we want to handle cases that would fuzzy-compare as equal, resulting in two elements being permitted through the match element instead of one. That would be no different from two conditional elements, but might not be the expected behaviour of a match element.

We could potentially allow it with a warning?

Comment thread internal/compiler/tests/syntax/match_element/float_error.slint Outdated
@R-Cramer4

Copy link
Copy Markdown
Contributor Author

I pulled the float error code into its own PR (#13399) so we can decide on that later. This PR now just has the two commits which hopefully can be merged.

Hash values when checking for duplicates/exhaustiveness instead of
running a O(N^2) search over them
Match statements are now covered in the NodeJS test driver as well
@0x6e
0x6e merged commit 62cdfb8 into slint-ui:master Sep 18, 2026
53 checks passed
@R-Cramer4
R-Cramer4 deleted the match-fixes branch September 18, 2026 14:46
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.

3 participants