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

cannot use if-expression on the left side of an indexexpr #22654

Closed
zeozeozeo opened this issue Oct 25, 2024 · 0 comments · Fixed by #22661
Closed

cannot use if-expression on the left side of an indexexpr #22654

zeozeozeo opened this issue Oct 25, 2024 · 0 comments · Fixed by #22661
Assignees
Labels
Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@zeozeozeo
Copy link
Contributor

zeozeozeo commented Oct 25, 2024

V doctor:

V full version: V 0.4.8 5c65e58.a454f06
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 10 cpus, 64bit, little endian, 

getwd: C:\Users\user\Downloads
vexe: C:\Users\user\Desktop\Code\v\v.exe
vexe mtime: 2024-10-25 17:08:19

vroot: OK, value: C:\Users\user\Desktop\Code\v
VMODULES: OK, value: C:\Users\user\.vmodules
VTMP: OK, value: C:\Users\user\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.1
Git vroot status: weekly.2024.43-30-ga454f064
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

What did you do?
./v -g -o vdbg cmd/v && ./vdbg test.v

fn main() {
    mut array_a := [1, 2, 3]
    mut array_b := [4, 5, 6]
    (if true { array_a } else { array_b })[0] = 999
    println(array_a)
}

What did you expect to see?

[999, 2, 3] printed to stdout or a better error message

What did you see instead?

test.v:4:6: error: unexpected expression `v.ast.IfExpr`
    2 |     mut array_a := [1, 2, 3]
    3 |     mut array_b := [4, 5, 6]
    4 |     (if true { array_a } else { array_b })[0] = 999
      |      ~~
    5 |     println(array_a)
    6 | }

Additional information

The following works, meaning that the result of if true { array_a } else { array_b } can be assigned to:

fn main() {
    mut array_a := [1, 2, 3]
    mut array_b := [4, 5, 6]
    mut arr := if true { array_a } else { array_b }
    arr[0] = 999
    println(array_a)
}

This issue may be related to #22652.

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-21103

@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants