diff --git a/ivtest/ivltests/br_gh670.v b/ivtest/ivltests/br_gh670.v new file mode 100644 index 000000000..4fc1bb206 --- /dev/null +++ b/ivtest/ivltests/br_gh670.v @@ -0,0 +1,25 @@ +// Test for GitHub issue #670 +// Class method can have the same name as the class +program main; + class test; + int value; + + // Method with same name as class - should be valid + function void test(); + $display("test method called"); + value = 42; + endfunction + endclass + + test tst; + + initial begin + tst = new(); + tst.test(); + if (tst.value !== 42) begin + $display("FAILED: value = %0d, expected 42", tst.value); + $finish; + end + $display("PASSED"); + end +endprogram diff --git a/ivtest/regress-sv.list b/ivtest/regress-sv.list index 8f4ea3733..127f58fa5 100644 --- a/ivtest/regress-sv.list +++ b/ivtest/regress-sv.list @@ -990,3 +990,4 @@ ipsdownsel_real_idx CE,-g2012 ivltests gold=ipsdownsel_real_idx.gold ipsupsel_real_idx CE,-g2012 ivltests gold=ipsupsel_real_idx.gold real_edges CE,-g2012 ivltests gold=real_edges.gold br_gh1112 CE,-g2009 ivltests gold=br_gh1112.gold +br_gh670 normal,-g2009 ivltests diff --git a/parse.y b/parse.y index d1767a86b..7a3897d6b 100644 --- a/parse.y +++ b/parse.y @@ -1582,7 +1582,7 @@ for_step_opt definitions in the func_body to take on the scope of the function instead of the module. */ function_declaration /* IEEE1800-2005: A.2.6 */ - : K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER ';' + : K_function lifetime_opt data_type_or_implicit_or_void identifier_name ';' { assert(current_function == 0); current_function = pform_push_function_scope(@1, $4, $2); } @@ -1602,7 +1602,7 @@ function_declaration /* IEEE1800-2005: A.2.6 */ delete[]$4; } - | K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER + | K_function lifetime_opt data_type_or_implicit_or_void identifier_name { assert(current_function == 0); current_function = pform_push_function_scope(@1, $4, $2); } @@ -1628,7 +1628,7 @@ function_declaration /* IEEE1800-2005: A.2.6 */ /* Detect and recover from some errors. */ - | K_function lifetime_opt data_type_or_implicit_or_void IDENTIFIER error K_endfunction + | K_function lifetime_opt data_type_or_implicit_or_void identifier_name error K_endfunction { /* */ if (current_function) { pform_pop_scope(); @@ -2442,7 +2442,7 @@ streaming_concatenation /* IEEE1800-2005: A.8.1 */ task_declaration /* IEEE1800-2005: A.2.7 */ - : K_task lifetime_opt IDENTIFIER ';' + : K_task lifetime_opt identifier_name ';' { assert(current_task == 0); current_task = pform_push_task_scope(@1, $3, $2); } @@ -2469,7 +2469,7 @@ task_declaration /* IEEE1800-2005: A.2.7 */ delete[]$3; } - | K_task lifetime_opt IDENTIFIER '(' + | K_task lifetime_opt identifier_name '(' { assert(current_task == 0); current_task = pform_push_task_scope(@1, $3, $2); } @@ -2498,7 +2498,7 @@ task_declaration /* IEEE1800-2005: A.2.7 */ delete[]$3; } - | K_task lifetime_opt IDENTIFIER error K_endtask + | K_task lifetime_opt identifier_name error K_endtask { if (current_task) { pform_pop_scope(); @@ -4468,7 +4468,7 @@ hierarchy_identifier $$->push_back(name_component_t(lex_strings.make($1))); delete[]$1; } - | hierarchy_identifier '.' IDENTIFIER + | hierarchy_identifier '.' identifier_name { pform_name_t * tmp = $1; tmp->push_back(name_component_t(lex_strings.make($3))); delete[]$3;