From 0637afd2849cc9b93dd9be43032c6a05f5cc9bf1 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 20 Jun 2026 16:12:28 -0700 Subject: [PATCH 1/2] Report error for class tasks used as expressions Class object method calls in expression context call func_def() without first checking that the resolved class method is a function. If the method is a task, func_def() triggers an assert instead of reporting a normal elaboration error. Check the method scope type before accessing the function definition and report an error for tasks. Signed-off-by: Lars-Peter Clausen --- elab_expr.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/elab_expr.cc b/elab_expr.cc index 604e8d99d..526119758 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -3410,6 +3410,14 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope, return 0; } + if (method->type() != NetScope::FUNC) { + cerr << get_fileline() << ": error: Method " << method_name + << " of class " << class_type->get_name() + << " is not a function." << endl; + des->errors++; + return nullptr; + } + const NetFuncDef*def = method->func_def(); ivl_assert(*this, def); From 449abb6bdaf2394508e8945fdbfc41264f8c1855 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 20 Jun 2026 16:12:45 -0700 Subject: [PATCH 2/2] Add regression test for class tasks used as expressions Check that using a class task through an object method call in expression context reports a compile/elaboration error instead of triggering an assert. Signed-off-by: Lars-Peter Clausen --- ivtest/ivltests/sv_class_task_expr_fail.v | 19 +++++++++++++++++++ ivtest/regress-vvp.list | 1 + ivtest/vvp_tests/sv_class_task_expr_fail.json | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 ivtest/ivltests/sv_class_task_expr_fail.v create mode 100644 ivtest/vvp_tests/sv_class_task_expr_fail.json diff --git a/ivtest/ivltests/sv_class_task_expr_fail.v b/ivtest/ivltests/sv_class_task_expr_fail.v new file mode 100644 index 000000000..261f8135e --- /dev/null +++ b/ivtest/ivltests/sv_class_task_expr_fail.v @@ -0,0 +1,19 @@ +// Check that using a class task as an expression reports an error. + +module test; + + class C; + task t; + endtask + endclass + + C c; + + initial begin + int x; + c = new; + x = c.t(); + $display("FAILED"); + end + +endmodule diff --git a/ivtest/regress-vvp.list b/ivtest/regress-vvp.list index df582b9e6..3ea8e5176 100644 --- a/ivtest/regress-vvp.list +++ b/ivtest/regress-vvp.list @@ -272,6 +272,7 @@ sv_class_prop_nest_obj1 vvp_tests/sv_class_prop_nest_obj1.json sv_class_prop_nest_real1 vvp_tests/sv_class_prop_nest_real1.json sv_class_prop_nest_str1 vvp_tests/sv_class_prop_nest_str1.json sv_class_prop_nest_vec1 vvp_tests/sv_class_prop_nest_vec1.json +sv_class_task_expr_fail vvp_tests/sv_class_task_expr_fail.json sv_const1 vvp_tests/sv_const1.json sv_const2 vvp_tests/sv_const2.json sv_const3 vvp_tests/sv_const3.json diff --git a/ivtest/vvp_tests/sv_class_task_expr_fail.json b/ivtest/vvp_tests/sv_class_task_expr_fail.json new file mode 100644 index 000000000..d3c18575f --- /dev/null +++ b/ivtest/vvp_tests/sv_class_task_expr_fail.json @@ -0,0 +1,9 @@ +{ + "type" : "CE", + "source" : "sv_class_task_expr_fail.v", + "iverilog-args" : [ "-g2005-sv" ], + "vlog95" : { + "__comment" : "Classes are not supported", + "type" : "CE" + } +}