Преглед изворни кода

* forbid the usage of Result(x) as function call, resolves #14248

git-svn-id: trunk@13492 -
florian пре 16 година
родитељ
комит
6c99746074
3 измењених фајлова са 18 додато и 2 уклоњено
  1. 1 0
      .gitattributes
  2. 3 2
      compiler/pexpr.pas
  3. 14 0
      tests/webtbf/tw14248.pp

+ 1 - 0
.gitattributes

@@ -8636,6 +8636,7 @@ tests/webtbf/tw1407.pp svneol=native#text/plain
 tests/webtbf/tw14104a.pp svneol=native#text/plain
 tests/webtbf/tw14104b.pp svneol=native#text/plain
 tests/webtbf/tw14104c.pp svneol=native#text/plain
+tests/webtbf/tw14248.pp svneol=native#text/plain
 tests/webtbf/tw1432.pp svneol=native#text/plain
 tests/webtbf/tw1467.pp svneol=native#text/plain
 tests/webtbf/tw1483.pp svneol=native#text/plain

+ 3 - 2
compiler/pexpr.pas

@@ -1339,6 +1339,8 @@ implementation
            { Access to funcret or need to call the function? }
            if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
               (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
+              { result(x) is not allowed }
+              not(vo_is_result in tabstractvarsym(srsym).varoptions) and
               (
                (token=_LKLAMMER) or
                (
@@ -1346,8 +1348,7 @@ implementation
                  (m_tp7 in current_settings.modeswitches) or
                  (m_delphi in current_settings.modeswitches)
                 ) and
-                (afterassignment or in_args) and
-                not(vo_is_result in tabstractvarsym(srsym).varoptions)
+                (afterassignment or in_args)
                )
               ) then
             begin

+ 14 - 0
tests/webtbf/tw14248.pp

@@ -0,0 +1,14 @@
+{ %fail }
+program Project1;
+{$mode objfpc}{$H+}
+
+function Foo(a: Integer): Integer;
+begin
+  dec(a);
+  if a < 0 then exit;
+  Result := Result(a);
+end;
+
+begin
+  Foo(10);
+end.