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: disallow Result callbacks functions like map/filter/all/any #21055

Merged
merged 6 commits into from
Apr 18, 2024

Conversation

Delta456
Copy link
Member

Fixes #21049

@Delta456 Delta456 marked this pull request as draft March 18, 2024 14:21
@spytheman
Copy link
Member

.map(f()!) should be allowed, since f()! is sugar for f() or { return err }, which is well defined.

@spytheman
Copy link
Member

spytheman commented Mar 28, 2024

The checker however should check whether f()! returns a valid type .
In other words, it should allow:
.map( f1()! ), for fn f1() !Type {
... but it should not allow:
.map( f2()! ) for fn f2() ! {

@Delta456
Copy link
Member Author

The checker however should check whether f()! returns a valid type . In other words, it should allow: .map( f1()! ), for fn f1() !Type { ... but it should not allow: .map( f2()! ) for fn f2() ! {

Fair

@Delta456 Delta456 marked this pull request as ready for review April 14, 2024 07:06
@Delta456 Delta456 requested a review from spytheman April 14, 2024 15:02
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.

Excellent work.
Sorry for the delay.

@spytheman spytheman merged commit d5517b5 into vlang:master Apr 18, 2024
56 checks passed
@Delta456 Delta456 deleted the map_result_fn branch April 18, 2024 19:08
@ttytm
Copy link
Member

ttytm commented Apr 18, 2024

Wanted to try to utilize it instead of an or block, I'm still running into a builder error here:

v/vlib/x/json2/decoder.v

Lines 292 to 294 in bccf660

// NOTE: Using `!` on `to_time()` inside the array method causes a builder error - 2024/04/01.
[]time.Time { typ.$(field.name) = arr.map(it.to_time() or { time.Time{} }) }
[]?time.Time { typ.$(field.name) = arr.map(?time.Time(it.to_time() or { time.Time{} })) }

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.

c error while trying to map it.wait() on a thread of arrays
3 participants