Browse Source

* fixed misplaced bracket in condition test that caused all blocks
in libraries to be parsed as if they were the main module block,
which in practice mainly mean that local variables with default
values were never initialisation (mantis #16949)

git-svn-id: trunk@15596 -

Jonas Maebe 15 years ago
parent
commit
5b0962b735
4 changed files with 44 additions and 3 deletions
  1. 2 0
      .gitattributes
  2. 2 3
      compiler/psub.pas
  3. 19 0
      tests/webtbs/tw16949a.pp
  4. 21 0
      tests/webtbs/tw16949b.pp

+ 2 - 0
.gitattributes

@@ -10544,6 +10544,8 @@ tests/webtbs/tw16861.pp svneol=native#text/plain
 tests/webtbs/tw16863.pp svneol=native#text/plain
 tests/webtbs/tw16874.pp svneol=native#text/plain
 tests/webtbs/tw16901.pp svneol=native#text/plain
+tests/webtbs/tw16949a.pp svneol=native#text/plain
+tests/webtbs/tw16949b.pp svneol=native#text/plain
 tests/webtbs/tw1696.pp svneol=native#text/plain
 tests/webtbs/tw1699.pp svneol=native#text/plain
 tests/webtbs/tw1709.pp svneol=native#text/plain

+ 2 - 3
compiler/psub.pas

@@ -186,9 +186,8 @@ implementation
          if (
              assigned(current_procinfo.procdef.localst) and
              (current_procinfo.procdef.localst.symtablelevel=main_program_level) and
-             (current_module.is_unit)
-            ) or
-            islibrary then
+             (current_module.is_unit or islibrary)
+            ) then
            begin
              if (token=_END) then
                 begin

+ 19 - 0
tests/webtbs/tw16949a.pp

@@ -0,0 +1,19 @@
+{ %norun }
+{ %target=win32,win64,wince,darwin,linux,freebsd,solaris,beos}
+
+library tw16949a;
+
+{$mode objfpc}{$H+}
+
+function foo: LongInt; cdecl;
+var
+ x: LongInt = 12345;
+begin
+ Result := x;
+end;
+
+exports
+ foo;
+
+begin
+end.

+ 21 - 0
tests/webtbs/tw16949b.pp

@@ -0,0 +1,21 @@
+{ %target=win32,win64,wince,darwin,linux,freebsd,solaris,beos}
+{ %needlibrary }
+
+program ptest;
+
+{$ifdef fpc}{$mode objfpc}{$H+}{$endif fpc}
+
+const
+{$if defined(windows) or defined(mswindows)}
+  libname='tw16949a.dll';
+{$else}
+  libname='tw16949a';
+  {$linklib tw16949a}
+{$ifend}
+
+function foo: LongInt; cdecl; external libname;
+
+begin
+  if foo<>12345 then
+    halt(1);
+end.