Browse Source

* don't warn about possible use of uninitialised function results of
parent procedures in nested procedures (bug 4675)

git-svn-id: trunk@2287 -

Jonas Maebe 19 years ago
parent
commit
f6864a653f
3 changed files with 54 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 2 1
      compiler/htypechk.pas
  3. 51 0
      tests/webtbs/tw4675.pp

+ 1 - 0
.gitattributes

@@ -6675,6 +6675,7 @@ tests/webtbs/tw4634.pp -text
 tests/webtbs/tw4635.pp svneol=native#text/plain
 tests/webtbs/tw4640.pp svneol=native#text/plain
 tests/webtbs/tw4669.pp svneol=native#text/plain
+tests/webtbs/tw4675.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 2 - 1
compiler/htypechk.pas

@@ -799,7 +799,8 @@ implementation
                            not(vo_is_external in hsym.varoptions) and
                            (hsym.owner.symtabletype in [parasymtable,localsymtable,staticsymtable]) and
                            ((hsym.owner=current_procinfo.procdef.localst) or
-                            (vo_is_funcret in hsym.varoptions)) then
+                            ((hsym.owner=current_procinfo.procdef.parast) and
+                             (vo_is_funcret in hsym.varoptions))) then
                           begin
                             if (vo_is_funcret in hsym.varoptions) then
                               begin

+ 51 - 0
tests/webtbs/tw4675.pp

@@ -0,0 +1,51 @@
+{ OPT=-Sew }
+
+{ Source provided for Free Pascal Bug Report 4675 }
+{ Submitted by "Vicnent Snijders" on  2006-01-09 }
+{ e-mail: [email protected] }
+program Project1;
+
+{$mode objfpc}{$H+}
+
+function GotHint_WantNoHint: string;
+  procedure Add(const s: string);
+  begin
+    Result := Result + s;
+  end;
+begin
+  if result = 'abc' then;
+  Result := '';
+  Add('Test');
+end;
+
+function GotNoHint_OK: string;
+var
+  a: string;
+  procedure Add(const s: string);
+  begin
+    a:= a+ s;
+  end;
+begin
+  a:='';
+  Add('Test');
+  Result:=a;
+end;
+
+function GotNoHint_WantHint: string;
+var
+  a: string;
+  procedure Add(const s: string);
+  begin
+    a:= a+ s;
+  end;
+begin
+  Add('Test');
+  Result:=a;
+end;
+
+begin
+  writeln(GotHint_WantNoHint);
+  writeln(GotNoHint_OK);
+  writeln(GotNoHint_WantHint);
+end.
+