From 407e9d173bc1801386fcb9a1cb9988c32ea0f8ee Mon Sep 17 00:00:00 2001 From: svenbarth Date: Tue, 9 Jul 2013 07:56:45 +0000 Subject: [PATCH] Fix for Mantis #17598. When extended syntax is off allow the result of constructors to be dropped when the constructor is called as an instance method instead of a class method. pstatmnt.pas, statement: * check whether the constructor is called as an instance or class method nflw.pas, tlabelnode.pass_1: * don't check the owner of the labelsym when there is none (happens with internally created labels like for e.g. exception handling) + added test git-svn-id: trunk@25068 - --- .gitattributes | 1 + compiler/nflw.pas | 2 ++ compiler/pstatmnt.pas | 10 ++++++++-- tests/webtbs/tw17598.pp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/webtbs/tw17598.pp diff --git a/.gitattributes b/.gitattributes index 1cee7d1542..625a1ad881 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13100,6 +13100,7 @@ tests/webtbs/tw17550.pp svneol=native#text/plain tests/webtbs/tw17560.pp svneol=native#text/plain tests/webtbs/tw1758.pp svneol=native#text/plain tests/webtbs/tw17591.pp svneol=native#text/plain +tests/webtbs/tw17598.pp svneol=native#text/pascal tests/webtbs/tw17604.pp svneol=native#text/plain tests/webtbs/tw17646.pp svneol=native#text/plain tests/webtbs/tw1765.pp svneol=native#text/plain diff --git a/compiler/nflw.pas b/compiler/nflw.pas index 1ae2708f38..4521c1fdb8 100644 --- a/compiler/nflw.pas +++ b/compiler/nflw.pas @@ -1874,6 +1874,8 @@ implementation if assigned(left) then firstpass(left); if (m_non_local_goto in current_settings.modeswitches) and + { the owner can be Nil for internal labels } + assigned(labsym.owner) and (current_procinfo.procdef.parast.symtablelevel<>labsym.owner.symtablelevel) then CGMessage(cg_e_labels_cannot_defined_outside_declaration_scope) end; diff --git a/compiler/pstatmnt.pas b/compiler/pstatmnt.pas index 9525b0a197..1c384a3cc3 100644 --- a/compiler/pstatmnt.pas +++ b/compiler/pstatmnt.pas @@ -1295,8 +1295,14 @@ implementation not(is_void(p.resultdef)) and { can be nil in case there was an error in the expression } assigned(tcallnode(p).procdefinition) and - not((tcallnode(p).procdefinition.proctypeoption=potype_constructor) and - is_object(tprocdef(tcallnode(p).procdefinition).struct)) then + { allow constructor calls to drop the result if they are + called as instance methods instead of class methods } + not( + (tcallnode(p).procdefinition.proctypeoption=potype_constructor) and + is_class_or_object(tprocdef(tcallnode(p).procdefinition).struct) and + assigned(tcallnode(p).methodpointer) and + (tnode(tcallnode(p).methodpointer).resultdef.typ=objectdef) + ) then Message(parser_e_illegal_expression); end; code:=p; diff --git a/tests/webtbs/tw17598.pp b/tests/webtbs/tw17598.pp new file mode 100644 index 0000000000..4b27236fc9 --- /dev/null +++ b/tests/webtbs/tw17598.pp @@ -0,0 +1,30 @@ +{ %NORUN } + +{$mode macpas} +{$extendedsyntax off} +{$modeswitch exceptions+} +{$modeswitch class+} + +program tw17598; + + uses + sysutils; + + type + EMyException = + class( Exception) + constructor Create( theMessage: Ansistring); + end; + +constructor EMyException.Create( theMessage: Ansistring); + begin + inherited Create( theMessage) + end; + +begin + try + raise EMyException.Create( 'my exception raised') + except + ShowException( ExceptObject, ExceptAddr) + end +end.