From a41bbf6901532d7bb1bac8b74e1e0ba4290a252b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 26 Dec 2025 04:02:54 +0800 Subject: [PATCH] fixes #25387; `embedsrc` breaks with Line Continuation (#25388) fixes #25387 https://stackoverflow.com/questions/30286253/how-to-escape-backslash-in-comment - adding a whitespace or `\t` after `\` breaks the `goto` block - `\* *\` doesn't support nesting, causing problems for using it in the Nim comments --- compiler/cgen.nim | 5 ++++- tests/ccgbugs/t25387.nim | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/ccgbugs/t25387.nim diff --git a/compiler/cgen.nim b/compiler/cgen.nim index c271cbda31..48bf1ad6e3 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -337,7 +337,10 @@ proc genLineDir(p: BProc, t: PNode) = let line = t.info.safeLineNm if optEmbedOrigSrc in p.config.globalOptions: - p.s(cpsStmts).add("//" & sourceLine(p.config, t.info) & "\L") + var code = sourceLine(p.config, t.info) + if code.endsWith('\\'): + code.add "#" + p.s(cpsStmts).add("// " & code & "\L") let lastFileIndex = p.lastLineInfo.fileIndex let freshLine = freshLineInfo(p, t.info) if freshLine: diff --git a/tests/ccgbugs/t25387.nim b/tests/ccgbugs/t25387.nim new file mode 100644 index 0000000000..d694e3351d --- /dev/null +++ b/tests/ccgbugs/t25387.nim @@ -0,0 +1,8 @@ +discard """ + matrix: "--embedsrc=on" +""" + +proc trim() = + let s = 10 + let x = s + 5 # user entered literal \ +trim() \ No newline at end of file