Browse Source

* don't crash when parsing exit(xxx) in a constructor (mantis #23110)

git-svn-id: trunk@22795 -
Jonas Maebe 12 years ago
parent
commit
1822c46d8a
3 changed files with 15 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 3 2
      compiler/pexpr.pas
  3. 11 0
      tests/webtbs/tw23110.pp

+ 1 - 0
.gitattributes

@@ -12930,6 +12930,7 @@ tests/webtbs/tw2305.pp svneol=native#text/plain
 tests/webtbs/tw2306.pp svneol=native#text/plain
 tests/webtbs/tw2306.pp svneol=native#text/plain
 tests/webtbs/tw2307.pp svneol=native#text/plain
 tests/webtbs/tw2307.pp svneol=native#text/plain
 tests/webtbs/tw2311.pp svneol=native#text/plain
 tests/webtbs/tw2311.pp svneol=native#text/plain
+tests/webtbs/tw23110.pp svneol=native#text/plain
 tests/webtbs/tw2317.pp svneol=native#text/plain
 tests/webtbs/tw2317.pp svneol=native#text/plain
 tests/webtbs/tw2318.pp svneol=native#text/plain
 tests/webtbs/tw2318.pp svneol=native#text/plain
 tests/webtbs/tw2318b.pp svneol=native#text/plain
 tests/webtbs/tw2318b.pp svneol=native#text/plain

+ 3 - 2
compiler/pexpr.pas

@@ -306,8 +306,9 @@ implementation
                         begin
                         begin
                           p1:=comp_expr(true,false);
                           p1:=comp_expr(true,false);
                           consume(_RKLAMMER);
                           consume(_RKLAMMER);
-                          if (not assigned(current_procinfo) or
-                              is_void(current_procinfo.procdef.returndef)) then
+                          if not assigned(current_procinfo) or
+                             (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
+                             is_void(current_procinfo.procdef.returndef) then
                             begin
                             begin
                               Message(parser_e_void_function);
                               Message(parser_e_void_function);
                               { recovery }
                               { recovery }

+ 11 - 0
tests/webtbs/tw23110.pp

@@ -0,0 +1,11 @@
+type TTest = object
+                constructor Init;
+             end;
+
+constructor TTest.Init;
+begin
+  exit (0);
+end;
+
+begin
+end.