mirror of
https://github.com/verilator/verilator.git
synced 2025-07-31 07:56:10 +00:00
Fix return in constructors (#3734)
This commit is contained in:
parent
a29d9469da
commit
cbf9cc8e5f
@ -234,7 +234,7 @@ private:
|
||||
return;
|
||||
} else if (!m_ftaskp) {
|
||||
nodep->v3error("Return isn't underneath a task or function");
|
||||
} else if (funcp && !nodep->lhsp()) {
|
||||
} else if (funcp && !nodep->lhsp() && !funcp->isConstructor()) {
|
||||
nodep->v3error("Return underneath a function should have return value");
|
||||
} else if (!funcp && nodep->lhsp()) {
|
||||
nodep->v3error("Return underneath a task shouldn't have return value");
|
||||
|
20
test_regress/t/t_class_new_return.pl
Executable file
20
test_regress/t/t_class_new_return.pl
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2022 by Antmicro Ltd. This program is free software; you
|
||||
# can redistribute it and/or modify it under the terms of either the GNU
|
||||
# Lesser General Public License Version 3 or the Perl Artistic License
|
||||
# Version 2.0.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(simulator => 1);
|
||||
|
||||
compile();
|
||||
|
||||
execute(
|
||||
check_finished => 1,
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
36
test_regress/t/t_class_new_return.v
Normal file
36
test_regress/t/t_class_new_return.v
Normal file
@ -0,0 +1,36 @@
|
||||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||
// any use, without warranty, 2022 by Antmicro Ltd.
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
module t (/*AUTOARG*/
|
||||
clk
|
||||
);
|
||||
|
||||
input clk;
|
||||
|
||||
class foo;
|
||||
int a;
|
||||
function new;
|
||||
a = 1;
|
||||
return;
|
||||
a = 2;
|
||||
endfunction
|
||||
function int get_a;
|
||||
return a;
|
||||
endfunction
|
||||
endclass
|
||||
|
||||
foo foo_i;
|
||||
initial foo_i = new;
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (foo_i.get_a() == 1) begin
|
||||
$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
else
|
||||
$stop;
|
||||
end
|
||||
endmodule
|
Loading…
Reference in New Issue
Block a user