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, orm: add error for unchecked option multi return types, fix undefined behavior #21106

Merged
merged 4 commits into from
Mar 28, 2024

Conversation

ttytm
Copy link
Member

@ttytm ttytm commented Mar 26, 2024

Fixes #17874
Fixes #21117
Due to the changes, a fix to the vlib orm module is included.

fn split(str string) ?(string, string) {
	return none
}

fn main() {
	foo, bar := split('foo/bar')
	println('${foo}.${bar}')
}

Will now throw:

error: split() returns `?(string, string)`, so it should have either an `or {}` block, or `?` at the end
    4 | 
    5 | fn main() {
    6 |     foo, bar := split('foo/bar')
      |                 ~~~~~~~~~~~~~~~~
    7 |     println('${foo}.${bar}')
    8 | }

Based on #21105 (After resolving it first, the PR should rebased)

Superseeds #20515. The PR is stale for a while, but took good steps towards the solution.

@JalonSolov
Copy link
Contributor

JalonSolov commented Mar 26, 2024

Not a good to idea mention tuples at all. V doesn't support tuples, only multi-returns.

@ttytm
Copy link
Member Author

ttytm commented Mar 26, 2024

Ok thanks @JalonSolov gonna update.
Wasn't sure as we have ast.Tuple and ast.TupleType and also the changelog mentions

@ttytm ttytm changed the title checker, orm: add error for unchecked tuple option return types, fix undefined behavior checker, orm: add error for unchecked option multi return types, fix undefined behavior Mar 26, 2024
@ttytm ttytm force-pushed the checker/fix-multi-ret-opt branch from fcc18da to f00c9e3 Compare March 27, 2024 12:43
@ttytm ttytm marked this pull request as ready for review March 27, 2024 12:47
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 🚀 .

@spytheman spytheman merged commit b98dca5 into vlang:master Mar 28, 2024
54 checks passed
@ttytm ttytm deleted the checker/fix-multi-ret-opt branch April 16, 2024 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants