Browse Source

* end of an include file works like a new line with regard to single line (//) comments, resolves #39912

florian 2 years ago
parent
commit
af1194de4d
3 changed files with 31 additions and 0 deletions
  1. 12 0
      compiler/scanner.pas
  2. 2 0
      tests/webtbs/ib39912.inc
  3. 17 0
      tests/webtbs/tb39912.pp

+ 12 - 0
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^;

+ 2 - 0
tests/webtbs/ib39912.inc

@@ -0,0 +1,2 @@
+inc(i);
+// 

+ 17 - 0
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.