Fix return in constructors (#3734)

This commit is contained in:
Ryszard Rozak 2022-11-09 12:32:22 +01:00 committed by GitHub
parent a29d9469da
commit cbf9cc8e5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 1 deletions

View File

@ -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");

View 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;

View 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