From 7c663af588c3cd3581d8e16b2fbbc02ce6ddfba1 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 18 Jan 2013 11:59:25 +0000 Subject: [PATCH] compiler: also don't allow record constructors with only default arguments git-svn-id: trunk@23438 - --- .gitattributes | 2 ++ compiler/pdecobj.pas | 2 +- compiler/ptype.pas | 2 +- tests/test/terecs17a.pp | 27 +++++++++++++++++++++++++++ tests/test/terecs18a.pp | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/test/terecs17a.pp create mode 100644 tests/test/terecs18a.pp diff --git a/.gitattributes b/.gitattributes index 681f439c70..4758a25098 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10811,7 +10811,9 @@ tests/test/terecs14.pp svneol=native#text/pascal tests/test/terecs15.pp svneol=native#text/pascal tests/test/terecs16.pp svneol=native#text/pascal tests/test/terecs17.pp svneol=native#text/pascal +tests/test/terecs17a.pp svneol=native#text/pascal tests/test/terecs18.pp svneol=native#text/pascal +tests/test/terecs18a.pp svneol=native#text/pascal tests/test/terecs2.pp svneol=native#text/pascal tests/test/terecs3.pp svneol=native#text/pascal tests/test/terecs4.pp svneol=native#text/pascal diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 36699d59f1..31670fe570 100644 --- a/compiler/pdecobj.pas +++ b/compiler/pdecobj.pas @@ -916,7 +916,7 @@ implementation result:=constructor_head; if is_objectpascal_helper(astruct) and is_record(tobjectdef(astruct).extendeddef) and - (result.maxparacount=0) then + (result.minparacount=0) then { as long as parameterless constructors aren't allowed in records they aren't allowed in helpers either } MessagePos(result.procsym.fileinfo,parser_e_no_parameterless_constructor_in_records); diff --git a/compiler/ptype.pas b/compiler/ptype.pas index 7eeed6c1a5..436ff7c0ef 100644 --- a/compiler/ptype.pas +++ b/compiler/ptype.pas @@ -720,7 +720,7 @@ implementation else begin pd:=constructor_head; - if pd.maxparacount = 0 then + if pd.minparacount = 0 then MessagePos(pd.procsym.fileinfo,parser_e_no_parameterless_constructor_in_records); end; diff --git a/tests/test/terecs17a.pp b/tests/test/terecs17a.pp new file mode 100644 index 0000000000..0f178e1df2 --- /dev/null +++ b/tests/test/terecs17a.pp @@ -0,0 +1,27 @@ +{ %FAIL } +{ %NORUN } +program terecs17a; + +{$mode delphi} + +type + + { TRec } + + TRec = record + X: Integer; + constructor Create(I: integer = 0); + end; + +{ TRec } + +constructor TRec.Create(I: integer = 0); +begin + +end; + +var + R: TRec; +begin + R := TRec.Create; +end. diff --git a/tests/test/terecs18a.pp b/tests/test/terecs18a.pp new file mode 100644 index 0000000000..1260975928 --- /dev/null +++ b/tests/test/terecs18a.pp @@ -0,0 +1,32 @@ +{ %FAIL } +{ %NORUN } +program terecs18a; + +{$mode delphi} + +type + + { TRec } + + TRec = record + X: Integer; + end; + + { TRecHelper } + + TRecHelper = record helper for TRec + constructor Create(I: Integer = 0); + end; + +{ TRecHelper } + +constructor TRecHelper.Create; +begin + +end; + +var + R: TRec; +begin + R := TRec.Create; +end. \ No newline at end of file