Skip to content

Fix false "failed to find library" warning for use clauses of generic packages - #1218

Open
tasgomes wants to merge 1 commit into
VUnit:masterfrom
tasgomes:fix/vhdl-parser-generic-package-use-clause
Open

Fix false "failed to find library" warning for use clauses of generic packages#1218
tasgomes wants to merge 1 commit into
VUnit:masterfrom
tasgomes:fix/vhdl-parser-generic-package-use-clause

Conversation

@tasgomes

Copy link
Copy Markdown
Contributor

Problem

When a design unit brings a locally declared generic package (or a local package instantiation) into scope with a use clause, the VHDL dependency scanner mistakes the package name for a library name and emits a spurious warning.

Example (VHDL-2008 generic package interface):

entity my_th is
    generic(
        package th_pkg is new work.some_pkg generic map (<>)
    );
end entity;

architecture a of my_th is
    use th_pkg.all;   -- th_pkg is a formal generic package, not a library
begin
end architecture;

This produces:

WARNING - /(...)/my_th.vhd: failed to find library 'th_pkg'

th_pkg is a formal generic-package parameter visible by its simple name, not a library. Compilation and simulation succeed, so only the (misleading) warning is wrong.

Root cause

VHDLReference._find_uses() parses use th_pkg.all; and records a package reference with library="th_pkg". The parser already recognizes the package th_pkg is new work.some_pkg ... instantiation (via PACKAGE_INSTANCE_PATTERN), but it never uses that knowledge to suppress the bogus library reference, so Project later fails to resolve library th_pkg and warns.

Fix

In VHDLReference.find(), collect the names introduced by local/generic package instantiations (the new_name group of PACKAGE_INSTANCE_PATTERN) and drop any package reference whose library matches one of them.

The real dependency (the reference to the instantiated package, e.g. work.some_pkg) has library="work" and is preserved, so the dependency graph is unchanged.

Tests

Added test_use_of_local_package_instance_is_not_a_library_reference in tests/unit/test_vhdl_parser.py, covering both a generic package formal and a local package instance, each followed by a use ...all; clause. It asserts that only the real package references remain. The test fails on main and passes with this change; the full parser suite still passes.

Notes

Fixes a false positive only; the dependency graph and compile order are unaffected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants