Files
lucisv/crates/vlog_refactor/tests/qa_warning_scope.rs
T
lucioandClaude Opus 5.5 9dc567c72a
ci / checks (push) Successful in 1m42s
ci / corpus (push) Successful in 32s
TODO §65.4: a hierarchical path rooted at a top-level module resolves through the workspace (conservative)
`tb.dut.g_sw[0].buf_q` written in a file that does not declare `tb` now
resolves like an instance path: the binder marks a dotted path's head
(Target::PathHead), resolve/root.rs answers a plain lexical miss with a
hierarchical external candidate, head_site roots the spine there, and
fold_path walks it — every hop a module/interface surface. find_references,
LSP references and rename see every segment; $root.tb works; a local `tb`
shadows. FACTS_FORMAT 22.

Rooted only when the root is provable (owner's ruling: conservative): not
when the head has an import candidate (so `import uvm_pkg::*` with uvm_pkg
outside the project stays warned — opentitan's DV force paths behave as
before), not from inside a class, not beside a macro that stands where a
declaration could (item, statement, port list), not when the root name is
also a package or ambiguous. The LSP rename set adds the files of the
path's root and middle hops (sources.rs, WorkspaceIndex::path_units_to).
An unresolved path is warned once.

QA (Opus) x2: F1-F4 and R1 silent-wrong-rename shapes fixed with tests;
QA's attack cases 1-6 each warned or correctly renamed; lucisv check hw
byte-identical to master. Completion after `tb.` deferred (TODO §65.8).
tools/gates.sh: PASS, 15 steps, 5 180 tests, corpus 814/820.
docs/features/top-rooted-paths.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 15:34:45 -07:00

526 lines
23 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! QA attacks on TODO §65.1 rework 3 (`rename/scoped.rs`): a module member's
//! bare spelling in another file's macro argument, `` `define`` body or
//! unstructured assertion is no longer warned about. The danger is a HIDDEN
//! real use — text that expands into the declaring module's scope from
//! another file. `docs/features/generate-label-rename/README.md`, QA log.
use std::path::PathBuf;
use vlog_refactor::rename;
fn workspace(files: &[(&str, &str)]) -> Vec<(PathBuf, String)> {
files.iter().map(|(name, text)| (PathBuf::from("/rtl").join(name), text.to_string())).collect()
}
/// Rename the first `logic <name>` (or `<prefix>` then `name`) in `file`;
/// the rewritten texts and the warnings, or the refusal.
fn run(
files: &[(&str, &str)],
file: &str,
prefix: &str,
name: &str,
new: &str,
) -> Result<(Vec<String>, Vec<String>), String> {
let sources = workspace(files);
let text = files.iter().find(|(n, _)| *n == file).map(|(_, t)| *t).expect("file");
let at = (text.find(prefix).expect("prefix") + prefix.len()) as u32;
let at = at + text[at as usize..].find(name).expect("name") as u32;
let edit = rename(&sources, &PathBuf::from("/rtl").join(file), at, new)?;
let texts = files
.iter()
.map(|(n, t)| {
let mut out = String::new();
let mut cursor = 0usize;
for e in edit.edits_for(&PathBuf::from("/rtl").join(n)) {
out.push_str(&t[cursor..e.range.start as usize]);
out.push_str(&e.new_text);
cursor = e.range.end as usize;
}
out.push_str(&t[cursor..]);
out
})
.collect();
Ok((texts, edit.warnings))
}
/// Whether some warning mentions `file` at `line` (`file:line` or `file at
/// line(s) … line`).
fn said(warnings: &[String], file: &str, line: u32) -> bool {
warnings.iter().any(|w| {
w.contains(&format!("{file}:{line}"))
|| (w.contains(file) && w.contains(&format!(" {line}")))
})
}
const ASSERT_DEFS: &str = "`define ASSERT(n, e) n: assert property (@(posedge clk) e);\n";
/// The opentitan `*_assert.svh` shape: the module includes a fragment whose
/// assertions name the module's own signals bare.
#[test]
fn a_bare_use_in_an_included_fragments_macro_argument_is_said() {
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
`include \"m_assert.svh\"
endmodule
";
let frag = " `ASSERT(StateKnown_A, !$isunknown(state_q))\n";
let files = [("defs.svh", ASSERT_DEFS), ("m.sv", module), ("m_assert.svh", frag)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(said(&warnings, "m_assert.svh", 1), "HIDDEN USE: {warnings:#?}");
}
/// The same fragment with the use in plain code, not a macro.
#[test]
fn a_bare_use_in_plain_included_code_is_renamed_or_said() {
let module = "module m (input logic clk, output logic o);
logic state_q;
`include \"m_body.svh\"
endmodule
";
let frag = " assign o = state_q;\n";
let files = [("m.sv", module), ("m_body.svh", frag)];
let (texts, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
// Lead's ruling on H4: said, not renamed (renaming inside included
// fragments is TODO §65.6).
assert_eq!(texts[1], frag, "the fragment is not edited");
assert!(said(&warnings, "m_body.svh", 1), "{warnings:#?}");
}
/// A header's `` `define`` whose body spells the net bare, invoked in the
/// declaring module: the expansion is a real use.
#[test]
fn a_bare_use_in_a_header_macro_body_invoked_in_the_module_is_said() {
let defs = "`define CHK assert property (@(posedge clk) state_q != 0);\n";
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
`CHK
endmodule
";
let files = [("chk.svh", defs), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(said(&warnings, "chk.svh", 1), "HIDDEN USE: {warnings:#?}");
}
/// A bind file's connection names the target's net bare inside a macro
/// argument — evaluated in the bound scope.
#[test]
fn a_bare_use_in_a_bind_connection_macro_argument_is_said() {
let defs = "`define Q(x) x\n";
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
endmodule
";
let chk = "module chk (input logic s);
endmodule
";
let bind = "module m_bind;
bind m chk u_chk (.s(`Q(state_q)));
endmodule
";
let files = [("defs.svh", defs), ("m.sv", module), ("chk.sv", chk), ("m_bind.sv", bind)];
let (texts, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(texts[3].contains("state_r") || said(&warnings, "m_bind.sv", 2), "{warnings:#?}");
}
/// Same file, several scopes: a function, a generate block and a nested
/// module see the net; an inner declaration of the same name shadows it.
#[test]
fn inside_the_declaring_file_the_lookup_respects_scopes_and_shadowing() {
let module = "module m (input logic clk);
logic state_q;
function automatic logic f();
return `Q(state_q);
endfunction
if (1) begin : g
assign x = `Q(state_q);
end
if (1) begin : h
logic state_q;
assign y = `Q(state_q);
end
endmodule
module other;
logic state_q;
assign z = `Q(state_q);
endmodule
";
let files = [("defs.svh", "`define Q(x) x\n"), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(said(&warnings, "m.sv", 4), "the function's use: {warnings:#?}");
assert!(said(&warnings, "m.sv", 7), "the generate block's use: {warnings:#?}");
assert!(!said(&warnings, "m.sv", 11), "shadowed by h's own state_q: {warnings:#?}");
assert!(!said(&warnings, "m.sv", 16), "the other module's own: {warnings:#?}");
}
/// Unstructured assertion text and `ifdef`-disabled text in the declaring
/// file.
#[test]
fn unparsed_assertion_and_ifdef_text_in_the_declaring_file_is_said() {
let module = "module m (input logic clk);
logic state_q;
always_ff @(posedge clk) state_q <= ~state_q;
a_weird: assert property (@(posedge clk) state_q |-> ##[1:$] $$$ state_q);
`ifdef NEVER
`Q(state_q)
`endif
endmodule
";
let files = [("defs.svh", "`define Q(x) x\n"), ("m.sv", module)];
let (texts, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(texts[1].contains("$$$ state_r") || said(&warnings, "m.sv", 4), "{warnings:#?}");
assert!(said(&warnings, "m.sv", 6), "the ifdef'd macro argument: {warnings:#?}");
}
/// Rework 2, R1: three files named `probe.sv` at different depths, each with
/// an unresolved path — each warning must name a findable file. (Since TODO
/// §65.4 a root some file declares resolves, so the set declares no `tb`.)
#[test]
fn recheck_three_same_named_files_are_each_named_by_their_path() {
let dut = "module dut_a;\n for (genvar i = 0; i < 2; i++) begin : g_sw\n logic q;\n end\nendmodule\n";
let probe = "module PROBE (output logic o);\n assign o = tb.dut.g_sw[0].q;\nendmodule\n";
let (p1, p2, p3) =
(probe.replace("PROBE", "p1"), probe.replace("PROBE", "p2"), probe.replace("PROBE", "p3"));
let files = [
("dut_a.sv", dut),
("probe.sv", p1.as_str()),
("x/probe.sv", p2.as_str()),
("x/y/z/probe.sv", p3.as_str()),
];
let (_, warnings) = run(&files, "dut_a.sv", "begin : ", "g_sw", "g_hw").expect("renames");
let paths: Vec<&String> = warnings.iter().filter(|w| w.contains("hierarchical path")).collect();
assert_eq!(paths.len(), 3, "{warnings:#?}");
for w in &paths {
let named = w.split(':').next().unwrap_or("");
assert!(named.ends_with("probe.sv") && named.contains('/'), "unfindable: {w}");
}
let mut named: Vec<&str> = paths.iter().map(|w| w.split(':').next().unwrap_or("")).collect();
named.dedup();
assert_eq!(named.len(), 3, "three distinct names: {warnings:#?}");
}
/// Rework 2, R3: three levels of same-label arms.
#[test]
fn recheck_three_level_same_label_arms_are_all_warned_about() {
let text = "module t (output logic o);
if (1) begin : a
if (1) begin : b
if (1) begin : c
logic x;
end
end
end else begin : a
if (1) begin : b
if (1) begin : c
logic x;
end
end else begin : b
if (1) begin : c
logic x;
end
end
end
assign o = a.b.c.x;
endmodule
";
let (_, warnings) = run(&[("t.sv", text)], "t.sv", "logic ", "x", "y").expect("renames");
for line in [11, 15] {
assert!(
warnings.iter().any(|w| w.contains(&format!("t.sv:{line}"))),
"{line}: {warnings:#?}"
);
}
// …and from the deepest-else arm.
let (_, warnings) = run(
&[("t.sv", text)],
"t.sv",
"end else begin : b\n if (1) begin : c\n logic ",
"x",
"y",
)
.expect("renames");
for line in [5, 11] {
assert!(
warnings.iter().any(|w| w.contains(&format!("t.sv:{line}"))),
"{line}: {warnings:#?}"
);
}
}
/// Rework 2, R2: an escaped net and an escaped label behind an unresolved root
/// — no file declares `tbe` — and, since TODO §65.4, renamed behind one that
/// is declared.
#[test]
fn recheck_escaped_net_and_label_paths_are_named() {
let dut = "module dut_e;\n logic \\n$q ;\n if (1) begin : \\g$sw \n logic q;\n end\nendmodule\n";
let tb = "module tbe;\n dut_e dut ();\nendmodule\n";
let probe = "module pe (output logic o, output logic p);\n assign o = tbe.dut.\\g$sw .q;\n assign p = tbe.dut.\\n$q ;\nendmodule\n";
let files = [("dut_e.sv", dut), ("pe.sv", probe)];
let (_, warnings) = run(&files, "dut_e.sv", "begin : ", "\\g$sw", "g_hw").expect("label");
assert!(warnings.iter().any(|w| w.starts_with("pe.sv:2:")), "{warnings:#?}");
let (_, warnings) = run(&files, "dut_e.sv", "logic ", "\\n$q", "n_q").expect("net");
assert!(warnings.iter().any(|w| w.starts_with("pe.sv:3:")), "{warnings:#?}");
let files = [("dut_e.sv", dut), ("tbe.sv", tb), ("pe.sv", probe)];
let (texts, warnings) = run(&files, "dut_e.sv", "logic ", "\\n$q", "n_q").expect("net");
assert_eq!(texts[2], probe.replace("\\n$q", "n_q"), "{warnings:#?}");
}
// ---------------------------------------------------------------------------
// Rework 4 (home set) attacks, 2026-09-30
// ---------------------------------------------------------------------------
const Q_DEFS: &str = "`define Q(x) x\n";
/// A module and a fragment it includes by `spelled`, the fragment naming
/// `state_q` bare in a macro argument; whether renaming `m.state_q` says so.
fn fragment_said(spelled: &str, frag_path: &str, extra: &[(&str, &str)]) -> (bool, Vec<String>) {
let module = format!(
"module m (input logic clk);\n logic state_q;\n always_ff @(posedge clk) state_q <= ~state_q;\n{spelled}\nendmodule\n"
);
let frag = " initial $display(\"%b\", `Q(state_q));\n";
let mut files: Vec<(&str, &str)> =
vec![("defs.svh", Q_DEFS), ("rtl/m.sv", &module), (frag_path, frag)];
files.extend_from_slice(extra);
let (_, warnings) = run(&files, "rtl/m.sv", "logic ", "state_q", "state_r").expect("renames");
let base = frag_path.rsplit('/').next().unwrap_or(frag_path);
(warnings.iter().any(|w| w.contains(base) && w.contains("macro invocation")), warnings)
}
#[test]
fn rework4_include_spellings_all_reach_the_fragment() {
for (spelled, path) in [
("`include \"../inc/m_assert.svh\"", "inc/m_assert.svh"),
("`include \"m_assert.svh\"", "deep/inc/dir/m_assert.svh"),
("`ifdef FOO\n`include \"m_assert.svh\"\n`endif", "rtl/m_assert.svh"),
("`include \"m_assert.svh\" // the assertions", "rtl/m_assert.svh"),
("`include \"m_assert.svh\"\r", "rtl/m_assert.svh"),
] {
let (ok, warnings) = fragment_said(spelled, path, &[]);
assert!(ok, "HIDDEN USE via {spelled:?} → {path}: {warnings:#?}");
}
}
#[test]
fn rework4_a_base_name_matching_two_files_takes_both() {
let other = ("other/m_assert.svh", " initial $display(\"%b\", `Q(state_q));\n");
let (ok, warnings) = fragment_said("`include \"m_assert.svh\"", "inc/m_assert.svh", &[other]);
assert!(ok, "{warnings:#?}");
let both =
warnings.iter().filter(|w| w.contains("m_assert.svh") && w.contains("macro")).count();
assert_eq!(both, 2, "both candidates are home: {warnings:#?}");
}
#[test]
fn rework4_three_level_includes_and_a_cycle_terminate_and_reach() {
let a = ("inc/a.svh", "`include \"b.svh\"\n");
let b = ("inc/b.svh", "`include \"m_assert.svh\"\n`include \"a.svh\"\n");
let (ok, warnings) = fragment_said("`include \"a.svh\"", "inc/m_assert.svh", &[a, b]);
assert!(ok, "three levels, with a cycle a → b → a: {warnings:#?}");
}
/// `` `include `FRAG `` — an include whose file name a macro builds.
#[test]
fn rework4_an_include_built_by_a_macro_is_followed_or_said() {
let defs = ("inc/paths.svh", "`define FRAG \"m_assert.svh\"\n");
let (ok, warnings) =
fragment_said("`include \"paths.svh\"\n`include `FRAG", "inc/m_assert.svh", &[defs]);
assert!(ok, "HIDDEN USE via `include `FRAG: {warnings:#?}");
}
/// The declaration sits in a fragment included by two modules: both
/// includers are home, and a bare use in either's macro argument is said.
#[test]
fn rework4_a_declaration_in_a_fragment_shared_by_two_modules() {
let decl = " logic shared_q;\n";
let m1 =
"module m1;\n`include \"decl.svh\"\n initial $display(\"%b\", `Q(shared_q));\nendmodule\n";
let m2 = "module m2;\n`include \"decl.svh\"\n assign o = shared_q;\nendmodule\n";
let files = [("defs.svh", Q_DEFS), ("decl.svh", decl), ("m1.sv", m1), ("m2.sv", m2)];
let result = run(&files, "decl.svh", "logic ", "shared_q", "shared_r");
let (_, warnings) = result.expect("renames");
assert!(said(&warnings, "m1.sv", 3), "m1's macro argument: {warnings:#?}");
assert!(said(&warnings, "m2.sv", 3), "m2's plain use: {warnings:#?}");
}
/// H2 closure and noise.
#[test]
fn rework4_define_bodies_reached_through_two_other_bodies() {
let hdr = "`define INNER state_q\n`define MID `INNER\n`define OUTER `MID\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `OUTER;
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
let bodies: Vec<&String> = warnings.iter().filter(|w| w.contains("body of macro")).collect();
assert!(
bodies.iter().any(|w| w.contains("`INNER`")),
"HIDDEN USE through two bodies: {warnings:#?}"
);
}
/// Noise, not a hidden use: a macro whose parameter is named like the net,
/// and a macro "invoked" only inside a string.
#[test]
fn rework4_a_parameter_named_like_the_net_and_a_string_invocation_are_not_news() {
let hdr = "`define PARAM(state_q) (state_q + 1)\n`define UNUSED state_q\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `PARAM(clk);
initial $display(\"`UNUSED\");
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(
!warnings.iter().any(|w| w.contains("`PARAM`") || w.contains("`UNUSED`")),
"{warnings:#?}"
);
}
/// H2 × H3: a bind file into the declaring module invokes a header macro
/// whose body spells the net bare.
#[test]
fn rework4_a_macro_invoked_inside_a_bind_into_the_unit_is_followed() {
let hdr = "`define SIG state_q\n";
let module = "module m (input logic clk);\n logic state_q;\nendmodule\n";
let chk = "module chk (input logic s);\nendmodule\n";
let bind = "module m_bind;\n bind m chk u_chk (.s(`SIG));\nendmodule\n";
let files = [("hdr.svh", hdr), ("m.sv", module), ("chk.sv", chk), ("m_bind.sv", bind)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(
warnings.iter().any(|w| w.contains("hdr.svh") || w.contains("m_bind.sv")),
"HIDDEN USE: {warnings:#?}"
);
}
/// H3 shapes: an instance path, an interface target, inside a generate.
#[test]
fn rework4_bind_by_path_to_an_interface_and_inside_a_generate() {
let ifc = "interface bus_if (input logic clk);\n logic state_q;\nendinterface\n";
let chk = "module chk (input logic s);\nendmodule\n";
let binds = "module binds;
bind bus_if chk u_a (.s(`Q(state_q)));
bind tb.u_bus chk u_b (.s(`Q(state_q)));
if (1) begin : g
bind bus_if chk u_c (.s(`Q(state_q)));
end
endmodule
";
let files = [("defs.svh", Q_DEFS), ("bus_if.sv", ifc), ("chk.sv", chk), ("binds.sv", binds)];
let (_, warnings) = run(&files, "bus_if.sv", "logic ", "state_q", "state_r").expect("renames");
for line in [2, 3, 5] {
assert!(said(&warnings, "binds.sv", line), "line {line}: {warnings:#?}");
}
}
/// H4: a fragment that declares its own `mem` is never rewritten; a fragment
/// only an unrelated module includes stays silent.
#[test]
fn rework4_fragment_uses_of_a_different_declaration_are_not_rewritten() {
let module = "module m;\n logic [7:0] mem;\n`include \"own.svh\"\nendmodule\n";
let own =
" function automatic int peek();\n logic [7:0] mem;\n return mem;\n endfunction\n";
let unrelated = "module u;\n logic [7:0] mem;\n`include \"far.svh\"\nendmodule\n";
let far = " initial mem = '0;\n";
let files = [("m.sv", module), ("own.svh", own), ("u.sv", unrelated), ("far.svh", far)];
let (texts, warnings) = run(&files, "m.sv", "logic [7:0] ", "mem", "mem_q").expect("renames");
assert_eq!(texts[1], own, "the fragment's own `mem` is never rewritten");
assert_eq!((texts[2].as_str(), texts[3].as_str()), (unrelated, far));
assert!(!warnings.iter().any(|w| w.contains("far.svh")), "{warnings:#?}");
}
// ---------------------------------------------------------------------------
// Rework 5 closing check, 2026-09-30
// ---------------------------------------------------------------------------
/// N1: renaming `sub.clk_i` edits `top` (its connection). `top` has no
/// `clk_i` of its own and spells one in a macro argument of the connection.
/// The bare spelling cannot name `sub`'s port; whatever is said, the port's
/// own module must still warn its own macro argument.
#[test]
fn rework5_an_edited_instantiator_without_its_own_name() {
let sub =
"module sub (input logic clk_i);\n initial $display(\"%b\", `Q(clk_i));\nendmodule\n";
let top = "module top (input logic c);\n sub u (.clk_i(`Q(clk_i)));\nendmodule\n";
let files = [("defs.svh", Q_DEFS), ("sub.sv", sub), ("top.sv", top)];
let (texts, warnings) = run(&files, "sub.sv", "logic ", "clk_i", "clk").expect("renames");
assert!(said(&warnings, "sub.sv", 2), "{warnings:#?}");
assert!(texts[2].contains(".clk("), "the connection's port name moves: {}", texts[2]);
}
/// N1: an edited file that also includes a fragment the declaring module
/// includes, and a nested module that re-declares the name.
#[test]
fn rework5_an_edited_file_sharing_a_fragment_or_nesting_a_redeclaration() {
let sub = "module sub (input logic clk_i);\n`include \"frag.svh\"\nendmodule\n";
let frag = " initial $display(\"%b\", `Q(clk_i));\n";
let top = "module top (input logic clk_i);\n`include \"frag.svh\"\n sub u (.clk_i);\n module inner;\n logic clk_i;\n initial $display(\"%b\", `Q(clk_i));\n endmodule\nendmodule\n";
let files = [("defs.svh", Q_DEFS), ("sub.sv", sub), ("frag.svh", frag), ("top.sv", top)];
let (_, warnings) = run(&files, "sub.sv", "logic ", "clk_i", "clk").expect("renames");
assert!(said(&warnings, "frag.svh", 1), "the shared fragment pastes into sub: {warnings:#?}");
assert!(!said(&warnings, "top.sv", 6), "inner's own clk_i: {warnings:#?}");
}
/// N2: a parameter named like the net silences only a body that has no
/// other way to the net. A path through the name in the body (`u_m.state_q`)
/// can reach it; 0.59.0 warned, rework 5 did not (QA P1: the parameter check
/// ran before `body_dotted` and the unscoped fallback). Fixed: both now come
/// first in `keeps_define_body`.
#[test]
fn rework5_a_shadowing_parameter_does_not_hide_a_dotted_body_spelling() {
let hdr = "`define PATHY(state_q) (state_q + u_m.state_q)\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `PATHY(clk);
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(warnings.iter().any(|w| w.contains("`PATHY`")), "the dotted path: {warnings:#?}");
}
/// A default argument spelling the name expands into the module when the
/// macro is invoked without it. Silent in 0.59.0 too (QA P2: default
/// arguments were never scanned); now scanned with the body.
#[test]
fn rework5_a_default_argument_spelling_the_name_is_said() {
let hdr = "`define DFLT(x = state_q) (x)\n";
let module = "module m (input logic clk, output logic [1:0] o);
logic state_q;
assign o = `DFLT();
endmodule
";
let files = [("hdr.svh", hdr), ("m.sv", module)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(
warnings.iter().any(|w| w.contains("`DFLT`") || w.contains("hdr.svh:1")),
"{warnings:#?}"
);
}
/// K2 through a two-level instance path, and N3 three include levels up.
#[test]
fn rework5_bind_by_two_level_path_and_three_levels_of_includers() {
let hdr = "`define SIG state_q\n";
let m = "module m;\n logic state_q;\nendmodule\n";
let chk = "module chk (input logic s);\nendmodule\n";
let bind = "module b;\n bind tb.u_top.u_m chk u_chk (.s(`SIG));\nendmodule\n";
let files = [("hdr.svh", hdr), ("m.sv", m), ("chk.sv", chk), ("b.sv", bind)];
let (_, warnings) = run(&files, "m.sv", "logic ", "state_q", "state_r").expect("renames");
assert!(warnings.iter().any(|w| w.contains("hdr.svh") || w.contains("b.sv")), "{warnings:#?}");
let body = " logic deep_q;\n initial $display(\"%b\", `Q(deep_q));\n";
let l1 = "`include \"body.svh\"\n";
let l2 = "`include \"l1.svh\"\n";
let l3 = "module top;\n`include \"l2.svh\"\n initial $display(\"%b\", `Q(deep_q));\n assign o = deep_q;\nendmodule\n";
let files =
[("defs.svh", Q_DEFS), ("body.svh", body), ("l1.svh", l1), ("l2.svh", l2), ("top.sv", l3)];
let (_, warnings) = run(&files, "body.svh", "logic ", "deep_q", "deep_r").expect("renames");
assert!(said(&warnings, "top.sv", 3), "three levels up, macro argument: {warnings:#?}");
assert!(said(&warnings, "top.sv", 4), "three levels up, plain use: {warnings:#?}");
}