From c147debda172087eb3ad3579b4a46c7d1ff0e9e4 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sun, 14 Apr 2019 20:47:43 +0000 Subject: [PATCH] * ensure that the correct amount of parameters is used for an operator overload (this is essentially important for unary operators that were declared with two arguments) git-svn-id: trunk@41868 - --- .gitattributes | 3 +++ compiler/htypechk.pas | 60 ++++++++++++++++++++++++------------------- tests/tbf/tb0268.pp | 13 ++++++++++ tests/tbf/tb0269.pp | 13 ++++++++++ tests/tbf/tb0270.pp | 13 ++++++++++ 5 files changed, 75 insertions(+), 27 deletions(-) create mode 100644 tests/tbf/tb0268.pp create mode 100644 tests/tbf/tb0269.pp create mode 100644 tests/tbf/tb0270.pp diff --git a/.gitattributes b/.gitattributes index 8e4c3756fa..9c24ac6308 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11161,6 +11161,9 @@ tests/tbf/tb0265.pp svneol=native#text/pascal tests/tbf/tb0266a.pp svneol=native#text/pascal tests/tbf/tb0266b.pp svneol=native#text/pascal tests/tbf/tb0267.pp svneol=native#text/plain +tests/tbf/tb0268.pp svneol=native#text/pascal +tests/tbf/tb0269.pp svneol=native#text/pascal +tests/tbf/tb0270.pp svneol=native#text/pascal tests/tbf/tb0588.pp svneol=native#text/pascal tests/tbf/ub0115.pp svneol=native#text/plain tests/tbf/ub0149.pp svneol=native#text/plain diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index 0a7e9d0d0a..950d56ae03 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -37,6 +37,8 @@ interface nod : tnodetype; inr : tinlinenumber; op_overloading_supported : boolean; + minargs : longint; + maxargs : longint; end; Ttok2opRec=record @@ -111,33 +113,33 @@ interface const tok2nodes=27; tok2node:array[1..tok2nodes] of ttok2noderec=( - (tok:_PLUS ;nod:addn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_MINUS ;nod:subn;inr:in_none;op_overloading_supported:true), { binary and unary overloading supported } - (tok:_STAR ;nod:muln;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_SLASH ;nod:slashn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_EQ ;nod:equaln;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_GT ;nod:gtn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_LT ;nod:ltn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_GTE ;nod:gten;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_LTE ;nod:lten;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_SYMDIF ;nod:symdifn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_STARSTAR ;nod:starstarn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_AS ;nod:asn;inr:in_none;op_overloading_supported:false), { binary overloading NOT supported } - (tok:_OP_IN ;nod:inn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_IS ;nod:isn;inr:in_none;op_overloading_supported:false), { binary overloading NOT supported } - (tok:_OP_OR ;nod:orn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_AND ;nod:andn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_DIV ;nod:divn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_NOT ;nod:notn;inr:in_none;op_overloading_supported:true), { unary overloading supported } - (tok:_OP_MOD ;nod:modn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_SHL ;nod:shln;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_SHR ;nod:shrn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_XOR ;nod:xorn;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_ASSIGNMENT ;nod:assignn;inr:in_none;op_overloading_supported:true), { unary overloading supported } - (tok:_OP_EXPLICIT;nod:assignn;inr:in_none;op_overloading_supported:true), { unary overloading supported } - (tok:_NE ;nod:unequaln;inr:in_none;op_overloading_supported:true), { binary overloading supported } - (tok:_OP_INC ;nod:inlinen;inr:in_inc_x;op_overloading_supported:true), { unary overloading supported } - (tok:_OP_DEC ;nod:inlinen;inr:in_dec_x;op_overloading_supported:true) { unary overloading supported } + (tok:_PLUS ;nod:addn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:2), { binary overloading supported } + (tok:_MINUS ;nod:subn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:2), { binary and unary overloading supported } + (tok:_STAR ;nod:muln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_SLASH ;nod:slashn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_EQ ;nod:equaln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_GT ;nod:gtn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_LT ;nod:ltn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_GTE ;nod:gten;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_LTE ;nod:lten;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_SYMDIF ;nod:symdifn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_STARSTAR ;nod:starstarn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_AS ;nod:asn;inr:in_none;op_overloading_supported:false;minargs:0;maxargs:0), { binary overloading NOT supported } + (tok:_OP_IN ;nod:inn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_IS ;nod:isn;inr:in_none;op_overloading_supported:false;minargs:0;maxargs:0), { binary overloading NOT supported } + (tok:_OP_OR ;nod:orn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_AND ;nod:andn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_DIV ;nod:divn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_NOT ;nod:notn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported } + (tok:_OP_MOD ;nod:modn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_SHL ;nod:shln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_SHR ;nod:shrn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_XOR ;nod:xorn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_ASSIGNMENT ;nod:assignn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported } + (tok:_OP_EXPLICIT;nod:assignn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported } + (tok:_NE ;nod:unequaln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported } + (tok:_OP_INC ;nod:inlinen;inr:in_inc_x;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported } + (tok:_OP_DEC ;nod:inlinen;inr:in_dec_x;op_overloading_supported:true;minargs:1;maxargs:1) { unary overloading supported } ); tok2ops=4; @@ -697,6 +699,8 @@ implementation begin result:= tok2node[i].op_overloading_supported and + (tok2node[i].minargs<=1) and + (tok2node[i].maxargs>=1) and isunaryoperatoroverloadable(tok2node[i].nod,tok2node[i].inr,ld); break; end; @@ -713,6 +717,8 @@ implementation rd:=tparavarsym(pf.parast.SymList[1]).vardef; result:= tok2node[i].op_overloading_supported and + (tok2node[i].minargs<=2) and + (tok2node[i].maxargs>=2) and isbinaryoperatoroverloadable(tok2node[i].nod,ld,nothingn,rd,nothingn); break; end; diff --git a/tests/tbf/tb0268.pp b/tests/tbf/tb0268.pp new file mode 100644 index 0000000000..c6bfc43b5d --- /dev/null +++ b/tests/tbf/tb0268.pp @@ -0,0 +1,13 @@ +{ %FAIL } + +program tb0268; + +{$mode objfpc} + +operator Not (aArg1: TObject; aArg2: TObject): TObject; +begin +end; + +begin + +end. diff --git a/tests/tbf/tb0269.pp b/tests/tbf/tb0269.pp new file mode 100644 index 0000000000..273b006076 --- /dev/null +++ b/tests/tbf/tb0269.pp @@ -0,0 +1,13 @@ +{ %FAIL } + +program tb0269; + +{$mode objfpc} + +operator + (aArg1: TObject; aArg2: TObject; aArg3: TObject): TObject; +begin +end; + +begin + +end. diff --git a/tests/tbf/tb0270.pp b/tests/tbf/tb0270.pp new file mode 100644 index 0000000000..5cc62a463d --- /dev/null +++ b/tests/tbf/tb0270.pp @@ -0,0 +1,13 @@ +{ %FAIL } + +program tb0270; + +{$mode objfpc} + +operator / (aArg1: TObject): TObject; +begin +end; + +begin + +end.