From af1194de4d5a33681608e7e745249db774e3a22a Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 19 Sep 2022 23:02:54 +0200 Subject: [PATCH] * end of an include file works like a new line with regard to single line (//) comments, resolves #39912 --- compiler/scanner.pas | 12 ++++++++++++ tests/webtbs/ib39912.inc | 2 ++ tests/webtbs/tb39912.pp | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/webtbs/ib39912.inc create mode 100644 tests/webtbs/tb39912.pp diff --git a/compiler/scanner.pas b/compiler/scanner.pas index 61af7d541b..aed1c30aa1 100644 --- a/compiler/scanner.pas +++ b/compiler/scanner.pas @@ -3641,6 +3641,8 @@ type procedure tscannerfile.reload; + var + wasmacro: Boolean; begin with inputfile do begin @@ -3698,6 +3700,7 @@ type end else begin + wasmacro:=inputfile.is_macro; { load eof position in tokenpos/current_filepos } gettokenpos; { close file } @@ -3713,6 +3716,15 @@ type tempopeninputfile; { status } Message1(scan_t_back_in,inputfile.name); + { end of include file is like a line break which ends e.g. also // style comments } + if not(wasmacro) then + begin + c:=#10; + { ... but we have to decrease the line number first because it is increased due to this + inserted line break later on } + dec(line_no); + exit; + end; end; { load next char } c:=inputpointer^; diff --git a/tests/webtbs/ib39912.inc b/tests/webtbs/ib39912.inc new file mode 100644 index 0000000000..7eab20c586 --- /dev/null +++ b/tests/webtbs/ib39912.inc @@ -0,0 +1,2 @@ +inc(i); +// \ No newline at end of file diff --git a/tests/webtbs/tb39912.pp b/tests/webtbs/tb39912.pp new file mode 100644 index 0000000000..36cc32efd5 --- /dev/null +++ b/tests/webtbs/tb39912.pp @@ -0,0 +1,17 @@ +{$macro on} +var + i: int32; + +begin + i := 0; + {$include ib39912.inc} {$include ib39912.inc} {$include ib39912.inc} + + {$define debugln := writeln} + debugln('i = ', i, ' (will be printed; must be 3).'); + if i<>3 then + halt(1); + + {$define debugln := //} + debugln('i = ', i, ' (will not be printed).'); + debugln halt(1); +end.