Skip to content

Commit f2cbfd0

Browse files
authored
Merge pull request #419 from diffblue/assign-to-variable
Verilog: better diagnostics on malformed assignments
2 parents 2dbe9a4 + 95bcd0c commit f2cbfd0

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
continuous_assignment_to_variable.v
3+
4+
^EXIT=2$
5+
^SIGNAL=0$
6+
^file continuous_assignment_to_variable\.v line 6: continuous assignment to a variable$
7+
^Identifier main\.some_reg is declared as bool on line 3\.$
8+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module main(input i);
2+
3+
reg some_reg;
4+
5+
// should error
6+
assign some_reg = i;
7+
8+
endmodule
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
procedural_assignment_to_net.v
3+
4+
^EXIT=2$
5+
^SIGNAL=0$
6+
^file procedural_assignment_to_net\.v line 6: procedural assignment to a net$
7+
^Identifier main\.some_net is declared as bool on line 3\.$
8+
--
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module main(input i);
2+
3+
wire some_net;
4+
5+
// should error
6+
always @i some_net = i;
7+
8+
endmodule

src/verilog/verilog_typecheck.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,10 @@ void verilog_typecheckt::check_lhs(
784784
if(symbol.is_state_var)
785785
{
786786
throw errort().with_location(lhs.source_location())
787-
<< "continuous assignment to register";
787+
<< "continuous assignment to a variable\n"
788+
<< "Identifier " << symbol.display_name() << " is declared as "
789+
<< to_string(symbol.type) << " on line " << symbol.location.get_line()
790+
<< '.';
788791
}
789792
else if(symbol.is_input && !symbol.is_output)
790793
{
@@ -799,7 +802,10 @@ void verilog_typecheckt::check_lhs(
799802
!symbol.is_lvalue)
800803
{
801804
throw errort().with_location(lhs.source_location())
802-
<< "assignment to non-register";
805+
<< "procedural assignment to a net\n"
806+
<< "Identifier " << symbol.display_name() << " is declared as "
807+
<< to_string(symbol.type) << " on line " << symbol.location.get_line()
808+
<< '.';
803809
}
804810

805811
break;

0 commit comments

Comments
 (0)