Add lint error on importing package within a class (#5634) (#5679)

This commit is contained in:
Nick Brereton 2025-01-07 16:52:44 -05:00 committed by GitHub
parent e171463fa2
commit 87d856339f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 55 additions and 13 deletions

View File

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

View File

@ -893,6 +893,13 @@ class LinkParseVisitor final : public VNVisitor {
}
iterateChildren(nodep);
}
void visit(AstPackageImport* nodep) override {
cleanFileline(nodep);
if (m_modp && !m_ftaskp && VN_IS(m_modp, Class)) {
nodep->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 2025 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
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, 2025 by Wilson Snyder
// SPDX-License-Identifier: CC0-1.0
package pkg;
endpackage
class genericClass;
import pkg::*;
endclass
module tb_top();
endmodule

View File

@ -262,23 +262,22 @@ interface z_if;
);
endinterface
class z_txn_class;
import z_pkg::*;
rand txn_type_t req_txn_type;
rand cid_t cid;
rand sid_t sid;
rand ctag_t ctag;
rand stag_t stag;
rand size_t size;
rand address_t address;
rand state_t state1;
rand state_t state2;
rand state_t state3;
rand z_pkg::txn_type_t req_txn_type;
rand z_pkg::cid_t cid;
rand z_pkg::sid_t sid;
rand z_pkg::ctag_t ctag;
rand z_pkg::stag_t stag;
rand z_pkg::size_t size;
rand z_pkg::address_t address;
rand z_pkg::state_t state1;
rand z_pkg::state_t state2;
rand z_pkg::state_t state3;
rand logic f1;
rand logic f2;
rand logic f3;
rand logic f4;
data_t data[];
mask_t mask[];
z_pkg::data_t data[];
z_pkg::mask_t mask[];
bit corrupt[];
logic [2:0] req_opcode;
endclass