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

Two escaped chars in bacticks break the builder. #20301

Closed
katekyy opened this issue Dec 29, 2023 · 1 comment · Fixed by #20304
Closed

Two escaped chars in bacticks break the builder. #20301

katekyy opened this issue Dec 29, 2023 · 1 comment · Fixed by #20304
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Compiler Panic The V compiler itself paniced. It should not, it should produce nice and readable errors instead. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Scanner Bugs/feature requests, that are related to the V scanner/lexer.

Comments

@katekyy
Copy link
Contributor

katekyy commented Dec 29, 2023

Describe the bug

It appears that when you put 2 escaped chars in a pair of bacticks, like you would with a rune, cgen (looking briefly at the stack trace) just breaks.

Reproduction Steps

fn main() {
	dump(`\n\t`)
}

Expected Behavior

main.v:2:7: error: invalid character literal `\n\t` => `\n\t` ([`\n`, `\t`]) (more than one character)
    1 | fn main() {
    2 |     dump(`\n\t`)
      |          ^
    3 | }
Details: 
main.v:2:7: details: use quotes for strings, backticks for characters
    1 | fn main() {
    2 |     dump(`\n\t`)
      |          ^
    3 | }

Current Behavior

V panic: substr(4, 2) out of bounds (len=4)
v hash: 680b0d4
/tmp/v_0/v2.15182888585928238289.tmp.c:21294: at _v_panic: Backtrace
/tmp/v_0/v2.15182888585928238289.tmp.c:24659: by string_substr
/tmp/v_0/v2.15182888585928238289.tmp.c:57682: by v__scanner__Scanner_decode_o_escapes
/tmp/v_0/v2.15182888585928238289.tmp.c:57818: by v__scanner__Scanner_ident_char
/tmp/v_0/v2.15182888585928238289.tmp.c:57033: by v__scanner__Scanner_text_scan
/tmp/v_0/v2.15182888585928238289.tmp.c:56821: by v__scanner__Scanner_scan_remaining_text
/tmp/v_0/v2.15182888585928238289.tmp.c:56809: by v__scanner__Scanner_scan_all_tokens_in_buffer
/tmp/v_0/v2.15182888585928238289.tmp.c:56331: by v__scanner__new_scanner_file
/tmp/v_0/v2.15182888585928238289.tmp.c:18321: by v__parser__parse_file
/tmp/v_0/v2.15182888585928238289.tmp.c:18659: by v__parser__parse_files
/tmp/v_0/v2.15182888585928238289.tmp.c:48933: by v__builder__Builder_front_stages
/tmp/v_0/v2.15182888585928238289.tmp.c:48987: by v__builder__Builder_front_and_middle_stages
/tmp/v_0/v2.15182888585928238289.tmp.c:51442: by v__builder__cbuilder__gen_c
/tmp/v_0/v2.15182888585928238289.tmp.c:51425: by v__builder__cbuilder__build_c
/tmp/v_0/v2.15182888585928238289.tmp.c:51415: by v__builder__cbuilder__compile_c
/tmp/v_0/v2.15182888585928238289.tmp.c:51321: by v__builder__Builder_rebuild
/tmp/v_0/v2.15182888585928238289.tmp.c:50426: by v__builder__compile
/tmp/v_0/v2.15182888585928238289.tmp.c:51756: by main__rebuild
/tmp/v_0/v2.15182888585928238289.tmp.c:51704: by main__main
/tmp/v_0/v2.15182888585928238289.tmp.c:52425: by main
Exited with error status 1
Please try again.

Possible Solution

Since this would still be an error, just don't do that.

Additional Information/Context

No response

V version

V 0.4.3 8f76a06

Environment details (OS name and version, etc.)

V full version: V 0.4.3 8f76a06.680b0d4
OS: linux, Linux version 6.1.68-1-lts (linux-lts@archlinux) (gcc (GCC) 13.2.1 20230801, GNU ld (GNU Binutils) 2.41.0) #1 SMP PREEMPT_DYNAMIC Wed, 13 Dec 2023 18:48:47 +0000
Processor: 8 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz

vroot: OK, value: /home/katekyy/.local/share/v
VMODULES: OK, value: /home/katekyy/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.0
Git vroot status: weekly.2023.52-14-g680b0d46
.git/config present: true

CC version: cc (GCC) 13.2.1 20230801
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

@katekyy katekyy added the Bug This tag is applied to issues which reports bugs. label Dec 29, 2023
@katekyy
Copy link
Contributor Author

katekyy commented Dec 29, 2023

Additionally. If you put a normal char after the escaped one, it thinks that there are 3 characters there. Well, technically there are, but that's not how the error message should look like.

                                                                   Here
                                                             vvvvvvvvvvvvvvv
main.v:2:7: error: invalid character literal `\na` => `\na` ([`\`, `n`, `a`]) (more than one character)
    1 | fn main() {
    2 |     dump(`\na`)
      |          ^
    3 | }
Details: 
main.v:2:7: details: use quotes for strings, backticks for characters
    1 | fn main() {
    2 |     dump(`\na`)
      |          ^
    3 | }

@shove70 shove70 self-assigned this Dec 29, 2023
@spytheman spytheman added Unit: Scanner Bugs/feature requests, that are related to the V scanner/lexer. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Status: Confirmed This bug has been confirmed to be valid by a contributor. Compiler Panic The V compiler itself paniced. It should not, it should produce nice and readable errors instead. labels Dec 29, 2023
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. Compiler Panic The V compiler itself paniced. It should not, it should produce nice and readable errors instead. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Scanner Bugs/feature requests, that are related to the V scanner/lexer.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants