Skip to content

all: add support for const ident in match range - #16526

Merged
spytheman merged 22 commits into
vlang:masterfrom
Delta456:const_range_expr
Nov 26, 2022
Merged

spytheman merged 22 commits into
vlang:masterfrom
Delta456:const_range_expr

Conversation

@Delta456

Copy link
Copy Markdown
Member

Implements #16480

Code Demonstration:

const start = 1
const end = 10

c := 2
num := match c {
	start...end {
		5
	}
	else {
		0
	}
}
println(num)

Output:

5

Comment thread doc/docs.md Resolved
Comment thread vlib/v/checker/match.v Resolved
Comment thread vlib/v/checker/match.v Resolved
Comment thread vlib/v/checker/match.v Resolved
Comment thread vlib/v/checker/match.v Resolved
Comment thread vlib/v/checker/match.v Resolved
Comment thread vlib/v/checker/match.v Resolved
Comment thread vlib/v/gen/c/match.v Resolved
@medvednikov

Copy link
Copy Markdown
Member

This seems to be too much code for such a basic feature.

Shouldn't the extra checks be unnecessary, since both parts of the expressions are already checked, for example?

Comment thread vlib/v/checker/match.v Resolved
@Delta456

Copy link
Copy Markdown
Member Author

This seems to be too much code for such a basic feature.

Shouldn't the extra checks be unnecessary, since both parts of the expressions are already checked, for example?

I also feel the code is too much but this implementation needs to have lots of checks, testing and examples to see every single case working.

Indeed, some extra checks might be unnecessary but hopefully we can minimise it by reviewing this PR or after getting this PR merged.

@spytheman

Copy link
Copy Markdown
Contributor

I've made some cleanups/fixes that generalize the checks here, but I am still waiting for the tests to pass locally.

@spytheman
spytheman marked this pull request as draft November 25, 2022 13:19
Comment thread CHANGELOG.md Resolved
@spytheman
spytheman marked this pull request as ready for review November 25, 2022 13:38
@Delta456
Delta456 requested a review from medvednikov November 25, 2022 18:13
@spytheman
spytheman merged commit a9b41d2 into vlang:master Nov 26, 2022
@Delta456
Delta456 deleted the const_range_expr branch November 26, 2022 07:01
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.

4 participants