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

checker: handle casted type matches #20111

Merged
merged 9 commits into from
Dec 14, 2023

Conversation

Delta456
Copy link
Member

@Delta456 Delta456 commented Dec 6, 2023

Closes #19248

🤖[deprecated] Generated by Copilot at cce27af

This pull request adds type checking and casting logic for match expressions in the vlib/v/checker module. It also adds several test files in the vlib/v/checker/tests directory to verify the correct behavior and error messages for different cases of match expressions with type casts.

🤖[deprecated] Generated by Copilot at cce27af

  • Add variables and logic to check type consistency and casting requirement in match expressions (link, link, link)
  • Declare explicit_cast_type and need_explicit_cast to store the expected type and the flag for explicit type casting in match branches (link)
  • Assign explicit_cast_type to the type of the first branch and check if it is a cast expression (link)
  • Compare the type and the casting of the rest of the branches with explicit_cast_type and need_explicit_cast and report errors if they are not consistent (link)
  • Add test files for different scenarios of type casting in match expressions (link, link, link, link, link, link)
    • Add test for match expression with incorrect type cast in one branch (match_incorrect_cast_branch_err.vv and match_incorrect_cast_branch_err.out) (link, link)
    • Add test for match expression with type cast only in the last branch (match_last_branch_only_casted.vv and match_last_branch_only_casted.out) (link, link)
    • Add test for match expression with no type cast in any branch except the first one (match_no_branch_cast_rest_casted_err.vv and match_no_branch_cast_rest_casted_err.out) (link, link)

@Delta456 Delta456 marked this pull request as draft December 6, 2023 21:55
vlib/v/checker/match.v Outdated Show resolved Hide resolved
vlib/v/checker/match.v Outdated Show resolved Hide resolved
vlib/v/checker/match.v Outdated Show resolved Hide resolved
@Delta456 Delta456 marked this pull request as ready for review December 7, 2023 07:20
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Good work.

@spytheman spytheman merged commit 68a6397 into vlang:master Dec 14, 2023
54 checks passed
@Delta456 Delta456 deleted the match_branch_check_casts branch December 14, 2023 17:06
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.

Checker should ask for explict cast in match expression
3 participants