Browse Source

pastojs: fixed unit without implementation

git-svn-id: trunk@47759 -
Mattias Gaertner 4 years ago
parent
commit
7e1cb64d5d

+ 12 - 6
packages/pastojs/src/fppas2js.pp

@@ -8186,7 +8186,8 @@ begin
           RemoveFromSourceElements(Src,ImplVarSt);
           // remove unneeded $mod.$implcode = function(){}
           RemoveFromSourceElements(Src,AssignSt);
-          HasImplUsesClause:=length(El.ImplementationSection.UsesClause)>0;
+          HasImplUsesClause:=(El.ImplementationSection<>nil)
+                         and (length(El.ImplementationSection.UsesClause)>0);
           end
         else
           begin
@@ -15236,6 +15237,7 @@ Var
     SectionScope: TPas2JSSectionScope;
     SectionCtx: TSectionContext;
     Src: TJSSourceElements;
+    ImplSect: TImplementationSection;
   begin
     SectionScope:=Section.CustomData as TPas2JSSectionScope;
     AContext.ScannerBoolSwitches:=SectionScope.BoolSwitches;
@@ -15254,8 +15256,9 @@ Var
       InitForwards(Section.Declarations,TSectionContext(AContext));
       if Section is TInterfaceSection then
         begin
-        InitForwards(TPasModule(Section.Parent).ImplementationSection.Declarations,
-                     TSectionContext(AContext));
+        ImplSect:=TPasModule(Section.Parent).ImplementationSection;
+        if ImplSect<>nil then
+          InitForwards(ImplSect.Declarations,TSectionContext(AContext));
         end;
       end;
   end;
@@ -17559,9 +17562,12 @@ begin
       end;
 
     // create implementation declarations
-    ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext);
-    if ImplDecl<>nil then
-      RaiseInconsistency(20170910175032,El); // elements should have been added directly
+    if El.ImplementationSection<>nil then
+      begin
+      ImplDecl:=ConvertDeclarations(El.ImplementationSection,ImplContext);
+      if ImplDecl<>nil then
+        RaiseInconsistency(20170910175032,El); // elements should have been added directly
+      end;
     IntfContext.ImplHeaderIndex:=ImplContext.HeaderIndex;
     Result:=FunDecl;
   finally

+ 10 - 6
packages/pastojs/src/pas2jsfiler.pp

@@ -8200,12 +8200,16 @@ var
   aModule: TPasModule;
 
   function CreateOrContinueSection(const PropName: string; var Section: TPasSection;
-     SectionClass: TPasSectionClass): boolean;
+     SectionClass: TPasSectionClass; MustExist: boolean): boolean;
   var
     SubObj: TJSONObject;
   begin
     if not ReadObject(Obj,PropName,SubObj,aModule) then
-      RaiseMsg(20180308142146,aModule);
+      begin
+      if MustExist then
+        RaiseMsg(20180308142146,aModule);
+      exit;
+      end;
     if Section=nil then
       Section:=TPasSection(CreateElement(SectionClass,'',aModule));
     ReadSection(SubObj,Section,aContext);
@@ -8259,7 +8263,7 @@ begin
       // start or continue ProgramSection
       Prog:=TPasProgram(aModule);
       if not CreateOrContinueSection('Program',TPasSection(Prog.ProgramSection),
-          TProgramSection) then
+          TProgramSection,true) then
         exit; // pending uses interfaces -> pause
       end
     else if aModule.ClassType=TPasLibrary then
@@ -8267,7 +8271,7 @@ begin
       // start or continue LibrarySection
       Lib:=TPasLibrary(aModule);
       if not CreateOrContinueSection('Library',TPasSection(Lib.LibrarySection),
-          TLibrarySection) then
+          TLibrarySection,true) then
         exit; // pending uses interfaces -> pause
       end
     else
@@ -8277,12 +8281,12 @@ begin
         begin
         // start or continue unit Interface
         if not CreateOrContinueSection('Interface',TPasSection(aModule.InterfaceSection),
-            TInterfaceSection) then
+            TInterfaceSection,true) then
           exit; // pending uses interfaces -> pause
         end;
       // start or continue unit Implementation
       if not CreateOrContinueSection('Implementation',TPasSection(aModule.ImplementationSection),
-          TImplementationSection) then
+          TImplementationSection,false) then
         exit; // pending uses interfaces -> pause
       end;
     if (Obj.Find('Init')<>nil)

+ 20 - 0
packages/pastojs/tests/tcprecompile.pas

@@ -54,6 +54,7 @@ type
   TTestCLI_Precompile = class(TCustomTestCLI_Precompile)
   published
     procedure TestPCU_EmptyUnit;
+    procedure TestPCU_UnitWithoutImplementation;
     procedure TestPCU_UTF8BOM;
     procedure TestPCU_ParamNS;
     procedure TestPCU_Overloads;
@@ -173,6 +174,25 @@ begin
   CheckPrecompile('test1.pas','src');
 end;
 
+procedure TTestCLI_Precompile.TestPCU_UnitWithoutImplementation;
+begin
+  AddUnit('src/system.pp',[''],['']);
+  AddFile('src/unit1.pas',
+    'unit unit1;'+LineEnding
+    +'interface'+LineEnding
+    +'end.'+LineEnding);
+  AddFile('src/unit2.pas',
+    'unit unit2;'+LineEnding
+    +'interface'+LineEnding
+    +'uses unit1;'+LineEnding
+    +'end.'+LineEnding);
+  AddFile('test1.pas',[
+    'uses unit2;',
+    'begin',
+    'end.']);
+  CheckPrecompile('test1.pas','src');
+end;
+
 procedure TTestCLI_Precompile.TestPCU_UTF8BOM;
 var
   aFile: TCLIFile;