Add error on class extending itself

This commit is contained in:
Wilson Snyder 2020-11-24 18:15:49 -05:00
parent e85a2e860e
commit 35374f09b4
4 changed files with 50 additions and 9 deletions

View File

@ -2774,6 +2774,10 @@ private:
if (AstClass* classp = VN_CAST(foundp->nodep(), Class)) { if (AstClass* classp = VN_CAST(foundp->nodep(), Class)) {
UINFO(8, "Import to " << nodep << " from export class " << classp UINFO(8, "Import to " << nodep << " from export class " << classp
<< endl); << endl);
if (classp == nodep) {
cextp->v3error("Attempting to extend class "
<< nodep->prettyNameQ() << " from itself");
} else {
AstClassRefDType* newp AstClassRefDType* newp
= new AstClassRefDType{nodep->fileline(), classp}; = new AstClassRefDType{nodep->fileline(), classp};
cextp->childDTypep(newp); cextp->childDTypep(newp);
@ -2783,6 +2787,7 @@ private:
m_curSymp->importFromClass(m_statep->symsp(), srcp); m_curSymp->importFromClass(m_statep->symsp(), srcp);
VL_DO_DANGLING(cpackagerefp->unlinkFrBack()->deleteTree(), VL_DO_DANGLING(cpackagerefp->unlinkFrBack()->deleteTree(),
cpackagerefp); cpackagerefp);
}
ok = true; ok = true;
} }
} }

View File

@ -0,0 +1,4 @@
%Error: t/t_class_extends_rec_bad.v:7:31: Attempting to extend class 'RecursiveExtCls' from itself
7 | class RecursiveExtCls extends RecursiveExtCls;
| ^~~~~~~~~~~~~~~
%Error: Exiting due to

View File

@ -0,0 +1,19 @@
#!/usr/bin/env perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2020 by Wilson Snyder. This program is free software; you
# can redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
scenarios(linter => 1);
lint(
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,13 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2020 by Wilson Snyder.
// SPDX-License-Identifier: CC0-1.0
class RecursiveExtCls extends RecursiveExtCls;
int i;
endclass
module t (/*AUTOARG*/);
RecursiveExtCls cls = new;
endmodule