浏览代码

* 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 年之前
父节点
当前提交
5b0962b735
共有 4 个文件被更改,包括 44 次插入3 次删除
  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/tw16863.pp svneol=native#text/plain
 tests/webtbs/tw16874.pp svneol=native#text/plain
 tests/webtbs/tw16874.pp svneol=native#text/plain
 tests/webtbs/tw16901.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/tw1696.pp svneol=native#text/plain
 tests/webtbs/tw1699.pp svneol=native#text/plain
 tests/webtbs/tw1699.pp svneol=native#text/plain
 tests/webtbs/tw1709.pp svneol=native#text/plain
 tests/webtbs/tw1709.pp svneol=native#text/plain

+ 2 - 3
compiler/psub.pas

@@ -186,9 +186,8 @@ implementation
          if (
          if (
              assigned(current_procinfo.procdef.localst) and
              assigned(current_procinfo.procdef.localst) and
              (current_procinfo.procdef.localst.symtablelevel=main_program_level) 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
            begin
              if (token=_END) then
              if (token=_END) then
                 begin
                 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.