@@ -578,6 +578,74 @@ TEST(call_java_record_varargs_accessor_has_array_return) {
578578 PASS ();
579579}
580580
581+ /* Comment extras in an otherwise empty parameter list must not create a
582+ * second, implicit accessor at the record component's source location. */
583+ TEST (call_java_record_commented_accessor_has_only_explicit_span ) {
584+ static const char * sources [] = {"record Value(int x) {\n"
585+ " public int x(/* explanation */) {\n"
586+ " return x;\n"
587+ " }\n"
588+ "}\n" ,
589+ "record Value(int x) {\n"
590+ " public int x(// explanation\n"
591+ " ) {\n"
592+ " return x;\n"
593+ " }\n"
594+ "}\n" };
595+ static const int end_lines [] = {4 , 5 };
596+ for (int fixture = 0 ; fixture < 2 ; fixture ++ ) {
597+ CBMFileResult * result =
598+ cbm_extract_file (sources [fixture ], (int )strlen (sources [fixture ]), CBM_LANG_JAVA ,
599+ "repro" , "Value.java" , 0 , NULL , NULL );
600+ ASSERT_NOT_NULL (result );
601+ int accessors = 0 ;
602+ int explicit_spans = 0 ;
603+ for (int i = 0 ; i < result -> defs .count ; i ++ ) {
604+ CBMDefinition * def = & result -> defs .items [i ];
605+ if (strcmp (def -> name , "x" ) == 0 && strcmp (def -> label , "Method" ) == 0 ) {
606+ accessors ++ ;
607+ if (def -> start_line == 2 && def -> end_line == end_lines [fixture ]) {
608+ explicit_spans ++ ;
609+ }
610+ }
611+ }
612+ cbm_free_result (result );
613+ ASSERT_EQ (accessors , 1 );
614+ ASSERT_EQ (explicit_spans , 1 );
615+ }
616+ PASS ();
617+ }
618+
619+ TEST (call_java_record_commented_overload_keeps_implicit_accessor ) {
620+ static const char source [] =
621+ "record Value(int x) {\n"
622+ " public int x(/* explanation */ int scale) { return x * scale; }\n"
623+ "}\n" ;
624+ CBMFileResult * result = cbm_extract_file (source , (int )strlen (source ), CBM_LANG_JAVA , "repro" ,
625+ "Value.java" , 0 , NULL , NULL );
626+ ASSERT_NOT_NULL (result );
627+ int methods = 0 ;
628+ int implicit_spans = 0 ;
629+ int overload_spans = 0 ;
630+ for (int i = 0 ; i < result -> defs .count ; i ++ ) {
631+ CBMDefinition * def = & result -> defs .items [i ];
632+ if (strcmp (def -> name , "x" ) == 0 && strcmp (def -> label , "Method" ) == 0 ) {
633+ methods ++ ;
634+ if (def -> start_line == 1 && def -> end_line == 1 ) {
635+ implicit_spans ++ ;
636+ }
637+ if (def -> start_line == 2 && def -> end_line == 2 ) {
638+ overload_spans ++ ;
639+ }
640+ }
641+ }
642+ cbm_free_result (result );
643+ ASSERT_EQ (methods , 2 );
644+ ASSERT_EQ (implicit_spans , 1 );
645+ ASSERT_EQ (overload_spans , 1 );
646+ PASS ();
647+ }
648+
581649SUITE (call_reference_contract ) {
582650 RUN_TEST (call_reference_typescript_direct_argument_is_exact );
583651 RUN_TEST (call_reference_kotlin_alias_argument_is_exact );
@@ -596,6 +664,8 @@ SUITE(call_reference_contract) {
596664 RUN_TEST (call_reference_go_ambiguous_promoted_method_stays_usage );
597665 RUN_TEST (call_java_record_accessor_binds_the_record );
598666 RUN_TEST (call_java_record_varargs_accessor_has_array_return );
667+ RUN_TEST (call_java_record_commented_accessor_has_only_explicit_span );
668+ RUN_TEST (call_java_record_commented_overload_keeps_implicit_accessor );
599669 RUN_TEST (call_java_static_import_does_not_call_field_sequential );
600670 RUN_TEST (call_java_static_import_does_not_call_field_parallel );
601671}
0 commit comments