Add lint error on importing package within a class

This commit is contained in:
Nick Brereton 2024-11-27 09:04:51 -05:00
parent ae990ebcda
commit ad60317751
5 changed files with 45 additions and 0 deletions

View File

@ -158,6 +158,7 @@ Nandu Raj
Nathan Graybeal
Nathan Kohagen
Nathan Myers
Nick Brereton
Nolan Poe
Oleh Maksymenko
Patrick Stewart

View File

@ -895,6 +895,15 @@ class LinkParseVisitor final : public VNVisitor {
}
iterateChildren(nodep);
}
void visit(AstClass* nodep) override {
cleanFileline(nodep);
for (AstNode* itemp = nodep->stmtsp(); itemp; itemp = itemp->nextp()) {
if (VN_IS(itemp, PackageImport)) {
itemp->v3error("Import statement directly within a class scope is illegal");
}
}
iterateChildren(nodep);
}
void visit(AstNode* nodep) override {
// Default: Just iterate

View File

@ -0,0 +1,4 @@
%Error: t/t_class_scope_import.v:11:14: Import statement directly within a class scope is illegal
11 | import pkg::*;
| ^~
%Error: Exiting due to

View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2024 by Nick Brereton. 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
import vltest_bootstrap
test.scenarios('linter')
test.lint(fails=True, expect_filename=test.golden_filename)
test.passes()

View File

@ -0,0 +1,15 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed under the Creative Commons Public Domain, for
// any use, without warranty, 2023 by Nick Brereton
// SPDX-License-Identifier: CC0-1.0
package pkg;
endpackage
class genericClass;
import pkg::*;
endclass
module tb_top();
endmodule