mirror of
https://github.com/verilator/verilator.git
synced 2024-12-29 10:47:34 +00:00
Add lint error on importing package within a class
This commit is contained in:
parent
ae990ebcda
commit
ad60317751
@ -158,6 +158,7 @@ Nandu Raj
|
||||
Nathan Graybeal
|
||||
Nathan Kohagen
|
||||
Nathan Myers
|
||||
Nick Brereton
|
||||
Nolan Poe
|
||||
Oleh Maksymenko
|
||||
Patrick Stewart
|
||||
|
@ -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
|
||||
|
4
test_regress/t/t_class_scope_import.out
Normal file
4
test_regress/t/t_class_scope_import.out
Normal 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
|
16
test_regress/t/t_class_scope_import.py
Executable file
16
test_regress/t/t_class_scope_import.py
Executable 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()
|
15
test_regress/t/t_class_scope_import.v
Normal file
15
test_regress/t/t_class_scope_import.v
Normal 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
|
Loading…
Reference in New Issue
Block a user