Skip to content

Commit c34cd05

Browse files
committed
Ensure protected type body map to non-body in signatures
1 parent a24ea32 commit c34cd05

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

vhdl_lang/src/analysis/named_entity/types.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ impl<'a> TypeEnt<'a> {
145145
match self.kind() {
146146
Type::Alias(alias) => alias.base_type(),
147147
Type::Subtype(subtype) => subtype.base_type(),
148+
Type::Protected(.., is_body) if *is_body => {
149+
// Never use the protected type body in signatures, use the non-body
150+
if let Related::DeclaredBy(other) = self.related {
151+
if let Some(typ) = TypeEnt::from_any(other) {
152+
typ
153+
} else {
154+
*self
155+
}
156+
} else {
157+
*self
158+
}
159+
}
148160
_ => *self,
149161
}
150162
}

vhdl_lang/src/analysis/tests/protected_type.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,45 @@ end package;",
290290
Some(&code.s("prot_t", 2).pos())
291291
);
292292
}
293+
294+
/// This was a bug where a procedure declared between the protected type and the body
295+
/// did not have the same signature as the definition which was after the body
296+
#[test]
297+
fn protected_type_and_body_result_in_the_same_signature() {
298+
let mut builder = LibraryBuilder::new();
299+
let code = builder.code(
300+
"libname",
301+
"
302+
package pkg is
303+
end package;
304+
305+
package body pkg is
306+
type prot_t is protected
307+
end protected;
308+
309+
procedure myproc(arg : prot_t);
310+
311+
type prot_t is protected body
312+
end protected body;
313+
314+
procedure myproc(arg : prot_t) is
315+
begin
316+
end procedure;
317+
318+
end package body;
319+
",
320+
);
321+
322+
let (root, diagnostics) = builder.get_analyzed_root();
323+
check_no_diagnostics(&diagnostics);
324+
325+
assert_eq!(
326+
root.find_all_references_pos(&code.s1("prot_t").pos()).len(),
327+
4
328+
);
329+
330+
assert_eq!(
331+
root.find_all_references_pos(&code.s1("myproc").pos()).len(),
332+
2
333+
);
334+
}

0 commit comments

Comments
 (0)