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

unchecked error handling for empty or blocks used in string interpolation x := "${ f() or {} }" #21176

Closed
spytheman opened this issue Apr 3, 2024 · 4 comments
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Result 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 Apr 3, 2024

V doctor:

V full version: V 0.4.5 872bcbc.55cafa9
OS: linux, Ubuntu 20.04.6 LTS
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz

getwd: /space/v/oo
vexe: /space/v/oo/v
vexe mtime: 2024-04-03 14:54:06

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

Git version: git version 2.42.0
Git vroot status: weekly.2024.14-8-g55cafa9b-dirty
.git/config present: true

CC version: cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
thirdparty/tcc status: thirdparty-linux-amd64 40e5cbb5

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

fn f() !string { return error('noo') }
value := 'value: "${f() or {}}" done'
println(value)

What did you expect to see?

a compiler error, similar to the one for assignment, requiring a non empty or block

What did you see instead?

value: "" done

Note that outside a string interpolation:

fn f() !string { return error('noo') }
value := f() or {}
println('value: "${value}"')

produces (as it should) an error:

x.v:2:14: error: assignment requires a non empty `or {}` block
    1 | fn f() !string { return error('noo') }
    2 | value := f() or {}
      |              ~~~~~
    3 | println('value: "${value}"')

The problem happens only inside string interpolations.

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.

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

I think to keep the language simple and readable, this simply should not be allowed.

@spytheman
Copy link
Member Author

Yes, the checker should have caught it.

@felipensp
Copy link
Member

This one is related to PR #17566

@felipensp felipensp self-assigned this Apr 14, 2024
@Delta456
Copy link
Member

Gives an error with the latest compilation of V.

file.v:2:25: error: assignment requires a non empty `or {}` block
    1 | fn f() !string { return error('noo') }
    2 | value := 'value: "${f() or {}}" done'
      |                         ~~~~~
    3 | println(value)

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. Result 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

4 participants