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

allow "unwrapped Option cannot be used in an infix expression" #23108

Closed
2 tasks
Le0Developer opened this issue Dec 9, 2024 · 1 comment · Fixed by #23113
Closed
2 tasks

allow "unwrapped Option cannot be used in an infix expression" #23108

Le0Developer opened this issue Dec 9, 2024 · 1 comment · Fixed by #23113
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`. Status: Confirmed This bug has been confirmed to be valid by a contributor. Type: Specification Everything related to the formal specification of how V should behave Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@Le0Developer
Copy link
Member

Le0Developer commented Dec 9, 2024

Describe the feature

This currently produces a checker error:

fn main() {
    x := []?int{len: 5, init: 1}

    println(x[0] == x[1])
}

(error: unwrapped Option cannot be used in an infix expression)

Use Case

Came up in Advent of Code day 9 when dealing with a []?int{}.

Proposed Solution

Fix the underlying cgen issue and then remove the checker error.

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.8 602b097.e32e9f7

Environment details (OS name and version, etc.)

V full version: V 0.4.8 602b097.e32e9f7
OS: macos, macOS, 15.1.1, 24B2091
Processor: 10 cpus, 64bit, little endian, Apple M4

getwd: /Users/leodev
vexe: /Users/leodev/p/v/v/v
vexe mtime: 2024-12-07 15:07:56

vroot: OK, value: /Users/leodev/p/v/v
VMODULES: OK, value: /Users/leodev/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.47.0
Git vroot status: weekly.2024.49-33-ge32e9f70 (10 commit(s) behind V master)
.git/config present: true

CC version: Apple clang version 16.0.0 (clang-1600.0.26.4)
emcc version: N/A
thirdparty/tcc status: thirdparty-macos-arm64 713692d4

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.

Huly®: V_0.6-21545

@spytheman spytheman added 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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Type: Specification Everything related to the formal specification of how V should behave Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Dec 9, 2024
@Le0Developer
Copy link
Member Author

Le0Developer commented Dec 9, 2024

For context, this is my AOC code which previously used []?int{} but now uses -1 as a magic null-value instead of options.
Linked is the line which triggered this checker error (going backwards in the list trying to find the first mismatching value)
https://github.com/vlang/adventofcode/blob/main/2024/09/leodev.v#L52

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`. Status: Confirmed This bug has been confirmed to be valid by a contributor. Type: Specification Everything related to the formal specification of how V should behave Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants