Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tuple pattern matching issue where only some elements would violate caps. #2658

Merged
merged 1 commit into from
Apr 19, 2018

Conversation

jemc
Copy link
Member

@jemc jemc commented Apr 18, 2018

When pattern-matching tuples that have the same number of elements,
ponyc was treating the entire match as violating capabilities when
only one of the elements was violating. In truth we should be able
to recognize that tuples are distinct from the other elements.

This patch fixes is_tuple_match_tuple to return MATCHTYPE_REJECT
as soon as any pairwise element comparison returns MATCHTYPE_REJECT.

The fix was pinpointed by @Praetonus when I discussed this issue with
him.

When pattern-matching tuples that have the same number of elements,
ponyc was treating the entire match as violating capabilities when
only one of the elements was violating. In truth we should be able
to recognize that tuples are distinct from the other elements.

This patch fixes `is_tuple_match_tuple` to return MATCHTYPE_REJECT
as soon as any pairwise element comparison returns MATCHTYPE_REJECT.

The fix was pinpointed by @Praetonus when I discussed this issue with
him.
@jemc jemc self-assigned this Apr 18, 2018
@jemc jemc added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Apr 18, 2018
@jemc
Copy link
Member Author

jemc commented Apr 18, 2018

For reference, here's my example that was failing to compile:
https://playground.ponylang.org/?gist=679bacf1177db8df7a8a6a2f273e5b56

@jemc jemc changed the title Fix tuple pattern matching issue where some elements would violate caps. Fix tuple pattern matching issue where only some elements would violate caps. Apr 18, 2018
Copy link
Member

@Praetonus Praetonus left a comment

Choose a reason for hiding this comment

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

Looks good to me.

In the future, we might want to extend this so that even if a previous element is denied, we continue to iterate to see if another element is rejected and should take precedence.

It would require changes to code generation when matching on values, as we must check the potentially denied element(s) last.

@jemc jemc merged commit 0051f75 into master Apr 19, 2018
@jemc jemc deleted the fix/match-tuple-reject-any branch April 19, 2018 14:05
ponylang-main added a commit that referenced this pull request Apr 19, 2018
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
…ps. (ponylang#2658)

When pattern-matching tuples that have the same number of elements,
ponyc was treating the entire match as violating capabilities when
only one of the elements was violating. In truth we should be able
to recognize that tuples are distinct from the other elements.

This patch fixes `is_tuple_match_tuple` to return MATCHTYPE_REJECT
as soon as any pairwise element comparison returns MATCHTYPE_REJECT.

The fix was pinpointed by @Praetonus when I discussed this issue with
him.
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants