Skip to content

Commit 636efb3

Browse files
authored
cgen: fix windows escape errors for comptime @ pseudo vars (#6977)
1 parent ee2a572 commit 636efb3

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

vlib/v/gen/comptime.v

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ fn cgen_attrs(attrs []table.Attr) []string {
112112

113113
fn (mut g Gen) comp_at(node ast.AtExpr) {
114114
if node.kind == .vmod_file {
115-
val := cnewlines(node.val.replace('\r', ''))
115+
val := cnewlines(node.val.replace('\r', '')).replace('\\', '\\\\')
116116
g.write('tos_lit("$val")')
117117
} else {
118-
g.write('tos_lit("$node.val")')
118+
val := node.val.replace('\\', '\\\\')
119+
g.write('tos_lit("$val")')
119120
}
120121
}
121122

vlib/v/scanner/scanner_at_literals_test.v renamed to vlib/v/tests/comptime_at_test.v

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
module scanner
2-
31
import os
2+
import v.pref
43

54
struct TestStruct {
65
test string
@@ -67,15 +66,7 @@ fn fn_name_mod_level_high_order(cb fn (int)) {
6766
fn test_at_file() {
6867
// Test @FILE
6968
f := os.file_name(@FILE)
70-
$if windows {
71-
// TODO all after Drive letter
72-
// no_drive := f.all_after(':')
73-
// TODO assert the variable name on Windows???
74-
// assert no_drive == 'scanner_at_literals_test.v'
75-
assert true
76-
} $else {
77-
assert f == 'scanner_at_literals_test.v'
78-
}
69+
assert f == 'comptime_at_test.v'
7970
}
8071

8172
fn test_at_fn() {
@@ -96,7 +87,7 @@ fn test_at_fn() {
9687

9788
fn test_at_mod() {
9889
// Test @MOD
99-
assert @MOD == 'scanner'
90+
assert @MOD == 'main'
10091
}
10192

10293
fn test_at_struct() {
@@ -123,3 +114,7 @@ fn test_vmod_file() {
123114
assert content.contains('version:')
124115
assert content.contains('description:')
125116
}
117+
118+
fn test_comptime_at() {
119+
assert @VEXE == pref.vexe_path()
120+
}

0 commit comments

Comments
 (0)