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 error cannot access fields of an Option for if optval != none { where optval is muttable #22936

Open
spytheman opened this issue Nov 21, 2024 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs. 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.

Comments

@spytheman
Copy link
Member

spytheman commented Nov 21, 2024

V doctor:

V full version: V 0.4.8 2fbb3df.58fc4de
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /home/delian/code/v
vexe: /home/delian/code/v/v
vexe mtime: 2024-11-21 18:27:40

vroot: OK, value: /home/delian/code/v
VMODULES: OK, value: /home/delian/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.46.0
Git vroot status: weekly.2024.47-13-g58fc4dea
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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

mut
entrykey := ?string(none)
if entrykey != none {
	println('entrykey is a string')
	println(entrykey.len)
	println(entrykey)
	if entrykey.len > 0 {
		println('ok')
	}
} else {
	println('entrykey was none')
}

What did you expect to see?

A compiled program. entrykey should be considered immutable inside the smartcasted block

What did you see instead?

pp.v:5:19: error: cannot access fields of an Option, handle the error with `or {...}` or propagate it with `?`
    3 | if entrykey != none {
    4 |     println('entrykey is a string')
    5 |     println(entrykey.len)
      |                      ~~~
    6 |     println(entrykey)
    7 |     if entrykey.len > 0 {
pp.v:7:14: error: cannot access fields of an Option, handle the error with `or {...}` or propagate it with `?`
    5 |     println(entrykey.len)
    6 |     println(entrykey)
    7 |     if entrykey.len > 0 {
      |                 ~~~
    8 |         println('ok')
    9 |     }

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

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker. Option Type Bugs/feature requests, that are related to `?Type`. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. labels Nov 21, 2024
@spytheman
Copy link
Member Author

Note: commenting the mut at the start, makes the program compile and run fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. 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.
Projects
None yet
Development

No branches or pull requests

1 participant