Skip to content

Commit 35072bc

Browse files
committed
Fix: Usage of the work library no longer cause circular dependency errors
1 parent 30cfd70 commit 35072bc

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

vhdl_lang/src/analysis/analyze.rs

+5
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
253253
library_name: &Symbol,
254254
scope: &Scope<'a>,
255255
) -> FatalResult {
256+
let library = self.get_library(library_name).unwrap();
257+
if library == self.work_library() {
258+
// This is the current library. All elements are already in scope.
259+
return Ok(());
260+
}
256261
let units = self.root.get_library_units(library_name).unwrap();
257262

258263
for unit in units.values() {

vhdl_lang/src/analysis/tests/circular_dependencies.rs

+42-16
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ package pkg2 is new work.gpkg generic map (g => true);
275275
#[test]
276276
fn use_library_all() {
277277
let mut builder = LibraryBuilder::new();
278-
let code = builder.code(
278+
builder.code(
279279
"libname",
280280
"
281281
use work.all;
@@ -290,20 +290,46 @@ package pkg2 is
290290
constant const : natural := 0;
291291
end package;",
292292
);
293-
let diagnostics = builder.analyze();
294-
check_diagnostics(
295-
diagnostics,
296-
vec![
297-
Diagnostic::new(
298-
code.s("pkg1", 2),
299-
"Found circular dependency",
300-
ErrorCode::CircularDependency,
301-
),
302-
Diagnostic::new(
303-
code.s("work.all", 1),
304-
"Found circular dependency",
305-
ErrorCode::CircularDependency,
306-
),
307-
],
293+
check_no_diagnostics(&builder.analyze());
294+
}
295+
296+
#[test]
297+
fn circular_dependency_own_library_all() {
298+
let mut builder = LibraryBuilder::new();
299+
builder.code(
300+
"lib",
301+
"
302+
library lib;
303+
use lib.all;
304+
305+
entity a is
306+
end entity;
307+
308+
architecture a_rtl of a is
309+
begin
310+
end;",
311+
);
312+
// This is allowed because 'lib' refers to it's own library
313+
// (similar to `library work` statement)
314+
check_no_diagnostics(&builder.analyze());
315+
}
316+
317+
#[test]
318+
fn circular_dependency_own_library() {
319+
let mut builder = LibraryBuilder::new();
320+
builder.code(
321+
"lib",
322+
"
323+
package foo is
324+
constant bar : bit := '0';
325+
end foo;
326+
327+
library lib;
328+
use lib.foo.bar;
329+
330+
entity a is
331+
end entity;
332+
",
308333
);
334+
check_no_diagnostics(&builder.analyze());
309335
}

0 commit comments

Comments
 (0)