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

Generate identifiers from conditions of match arms #380

Merged
merged 2 commits into from
Dec 22, 2022

Conversation

JSAbrahams
Copy link
Owner

@JSAbrahams JSAbrahams commented Dec 22, 2022

Summary

Match arms treated same way as if arms:

  • For each new arm create new constraint set
  • Use similar logic to for loop variable initialisation.

In future should have way to have some sort of union between constraints, much like env.
This allows us to type check all possible execution paths.

When we implementing pattern matching this system will need to be extended.

Added Tests

Happy

  • Variable only declared in condition of match arm usable in arm body.

Sad

  • Shadow system does not delete outer variables of match.
    Started writing this while creating system of environment unions between match body arms.
    However, I don't think that we actually want this behaviour.

Match arms treated same way as if arms:
- For each new arm create new constraint set
- Use similar logic to for loop variable
  initialisation.

In future should have way to have some sort of
union between constraints, much like env.
This allows us to type check all possible
execution paths.
@JSAbrahams JSAbrahams added enhancement: check New feature in the type check module bug: check Something in the type check module isn't working (as intended) labels Dec 22, 2022
@JSAbrahams JSAbrahams added this to the v0.3.5 | Error handling milestone Dec 22, 2022
@JSAbrahams JSAbrahams self-assigned this Dec 22, 2022
@codecov
Copy link

codecov bot commented Dec 22, 2022

Codecov Report

Merging #380 (7db045b) into develop (63cc218) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop     #380      +/-   ##
===========================================
+ Coverage    87.00%   87.06%   +0.06%     
===========================================
  Files          109      109              
  Lines        11950    12014      +64     
===========================================
+ Hits         10397    10460      +63     
- Misses        1553     1554       +1     
Impacted Files Coverage Δ
src/check/constrain/generate/control_flow.rs 93.40% <100.00%> (+1.36%) ⬆️
src/check/constrain/generate/expression.rs 94.28% <100.00%> (+1.42%) ⬆️
src/check/constrain/generate/mod.rs 91.93% <100.00%> (ø)
src/parse/expr_or_stmt.rs 94.38% <0.00%> (-0.62%) ⬇️
src/parse/ast/node.rs 79.77% <0.00%> (-0.11%) ⬇️
src/check/ast/mod.rs 93.69% <0.00%> (-0.06%) ⬇️
src/check/context/clss/generic.rs 93.15% <0.00%> (-0.04%) ⬇️
src/generate/ast/mod.rs 92.82% <0.00%> (-0.04%) ⬇️
src/check/ast/node.rs 95.75% <0.00%> (-0.02%) ⬇️
src/parse/block.rs 100.00% <0.00%> (ø)
... and 9 more

@JSAbrahams JSAbrahams marked this pull request as ready for review December 22, 2022 15:56
@JSAbrahams JSAbrahams changed the title Generate identifiers for conditions of match arms Generate identifiers from conditions of match arms Dec 22, 2022
@JSAbrahams JSAbrahams mentioned this pull request Dec 22, 2022
@@ -0,0 +1,5 @@
match 10
n =>
print("10")
Copy link
Owner Author

Choose a reason for hiding this comment

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

What about a test where we use an undefined variable in match arm body
Also one where we shadow a variable, but use it in the same manner as we would've the outer variable (e.g. assuming it is an Int while it is a String)

Copy link
Owner Author

Choose a reason for hiding this comment

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

No system for the second, though this is somewhat related to #375

@JSAbrahams JSAbrahams merged commit a9aed8a into develop Dec 22, 2022
@JSAbrahams JSAbrahams deleted the gen-identifiers-match branch December 22, 2022 23:06
JSAbrahams added a commit that referenced this pull request Dec 28, 2022
* Generate ids for variables in match arm conds

Match arms treated same way as if arms:
- For each new arm create new constraint set
- Use similar logic to for loop variable
  initialisation.

In future should have way to have some sort of
union between constraints, much like env.
This allows us to type check all possible
execution paths.

* Test undefined variable in match arm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: check Something in the type check module isn't working (as intended) enhancement: check New feature in the type check module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant