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

Optional inference in match expression #23831

Closed
2 tasks
jorgeluismireles opened this issue Feb 28, 2025 · 2 comments · Fixed by #23833
Closed
2 tasks

Optional inference in match expression #23831

jorgeluismireles opened this issue Feb 28, 2025 · 2 comments · Fixed by #23833
Assignees
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one. Option Type Bugs/feature requests, that are related to `?Type`. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Feb 28, 2025

Describe the feature

This is an extension of issue #23827

Infer as possible the match cases for optionals

Use Case

For returning none we need explicity set ?int(none)

fn a(cond int) {
	v:= match cond {
		0 {
			?int(none)
		}
		1 {
			1
		}
		else {
			1000
		}
	}
	println('${v}')
}

a(2)

Proposed Solution

Infer the none from ?int(none) to have this simpler form:

fn a(cond int) {
	v:= match cond {
		0 {
			none
		}
		1 {
			1
		}
		else {
			1000
		}
	}
	println('${v}')
}

a(2)

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V 0.4.9 5f5e48e

Environment details (OS name and version, etc.)

https://play.vlang.io/p/04cc0c924c

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Copy link

Connected to Huly®: V_0.6-22236

@jorgeluismireles
Copy link
Author

Is worth to mention that when the match is returned by a function with its return specified, single none already works:

fn a(cond int) ?int {
	return match cond {
		0 {
			none
		}
		1 {
			1
		}
		else {
			1000
		}
	}
}
println('${a(2)}')

@felipensp felipensp self-assigned this Feb 28, 2025
@felipensp felipensp added Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one. Unit: Checker Bugs/feature requests, that are related to the type checker. Option Type Bugs/feature requests, that are related to `?Type`. labels Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature/Enhancement Request This issue is made to request a feature or an enhancement to an existing one. Option Type Bugs/feature requests, that are related to `?Type`. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants