diff --git a/packages/fcl-passrc/src/pscanner.pp b/packages/fcl-passrc/src/pscanner.pp index 5cb904db30..8b89ad7bb9 100644 --- a/packages/fcl-passrc/src/pscanner.pp +++ b/packages/fcl-passrc/src/pscanner.pp @@ -2735,10 +2735,10 @@ begin begin if FIncludeStack.Count > 0 then begin - CurSourceFile.{$ifdef pas2js}Destroy{$else}Free{$endif}; IncludeStackItem := TIncludeStackItem(FIncludeStack[FIncludeStack.Count - 1]); FIncludeStack.Delete(FIncludeStack.Count - 1); + CurSourceFile.{$ifdef pas2js}Destroy{$else}Free{$endif}; FCurSourceFile := IncludeStackItem.SourceFile; FCurFilename := IncludeStackItem.Filename; FCurToken := IncludeStackItem.Token; @@ -3078,6 +3078,8 @@ end; procedure TPascalScanner.HandleIncludeFile(Param: String); +var + NewSourceFile: TLineReader; begin if Length(Param)>1 then begin @@ -3088,10 +3090,12 @@ begin Param:=copy(Param,2,length(Param)-2); end; end; - FCurSourceFile := FileResolver.FindIncludeFile(Param); - if not Assigned(FCurSourceFile) then + NewSourceFile := FileResolver.FindIncludeFile(Param); + if not Assigned(NewSourceFile) then Error(nErrIncludeFileNotFound, SErrIncludeFileNotFound, [Param]); + PushStackItem; + FCurSourceFile:=NewSourceFile; FCurFilename := Param; if FCurSourceFile is TFileLineReader then FCurFilename := TFileLineReader(FCurSourceFile).Filename; // nicer error messages diff --git a/packages/pastojs/src/pas2jscompiler.pp b/packages/pastojs/src/pas2jscompiler.pp index 27cc176f31..a5b43b90e8 100644 --- a/packages/pastojs/src/pas2jscompiler.pp +++ b/packages/pastojs/src/pas2jscompiler.pp @@ -1276,7 +1276,6 @@ begin Log.DebugLogWriteLn(PasModule.GetDeclaration(true)); end; - if{$IFDEF HasPas2jsFiler}PCUReader=nil{$ELSE}true{$ENDIF} then begin // read source module (instead of precompiled module) diff --git a/packages/pastojs/src/pas2jsfilecache.pp b/packages/pastojs/src/pas2jsfilecache.pp index e5f91c39f7..fa81ef5083 100644 --- a/packages/pastojs/src/pas2jsfilecache.pp +++ b/packages/pastojs/src/pas2jsfilecache.pp @@ -1313,7 +1313,7 @@ begin Filename:=FindIncludeFileName(aFilename); if Filename='' then exit; try - Result := TFileLineReader.Create(Filename); + Result:=FindSourceFile(Filename); except // error is shown in the scanner, which has the context information end;