@@ -916,6 +916,52 @@ TEST(csharp_constructor_of_type_named_extension) {
916916 PASS();
917917}
918918
919+ /* Escaping a type identifier does not change its constructor's identity. */
920+ TEST(csharp_constructor_of_escaped_type_named_extension) {
921+ const char *src = "namespace App { public class @extension { "
922+ "public extension() { int ConstructorLocal() => 1; } } }";
923+ CBMFileResult *r = extract(src, CBM_LANG_CSHARP, "t", "extension.cs");
924+ ASSERT_NOT_NULL(r);
925+ ASSERT_FALSE(r->has_error);
926+ ASSERT(has_def(r, "Method", "extension"));
927+ ASSERT_FALSE(has_def(r, "Method", "ConstructorLocal"));
928+ cbm_free_result(r);
929+ PASS();
930+ }
931+
932+ /* All conditional branches expose extension members, but method-local
933+ * functions must never be promoted to members of the enclosing type. */
934+ TEST(csharp_extension_block_conditional_members) {
935+ const char *src = "public static class TextExtensions\n"
936+ "{\n"
937+ " extension(string text)\n"
938+ " {\n"
939+ "#if FIRST\n"
940+ " public int First() { int Nested() => 1; return Nested(); }\n"
941+ "#elif SECOND\n"
942+ " public int Second() => 2;\n"
943+ "#else\n"
944+ "#if NESTED\n"
945+ " public int Third() => 3;\n"
946+ "#else\n"
947+ " public int Fourth() => 4;\n"
948+ "#endif\n"
949+ "#endif\n"
950+ " }\n"
951+ "}\n";
952+ CBMFileResult *r = extract(src, CBM_LANG_CSHARP, "t", "TextExtensions.cs");
953+ ASSERT_NOT_NULL(r);
954+ ASSERT_FALSE(r->has_error);
955+ ASSERT(has_def(r, "Method", "First"));
956+ ASSERT(has_def(r, "Method", "Second"));
957+ ASSERT(has_def(r, "Method", "Third"));
958+ ASSERT(has_def(r, "Method", "Fourth"));
959+ ASSERT_FALSE(has_def_any(r, "extension"));
960+ ASSERT_FALSE(has_def(r, "Method", "Nested"));
961+ cbm_free_result(r);
962+ PASS();
963+ }
964+
919965/* --- Swift --- */
920966TEST(swift_class) {
921967 CBMFileResult *r = extract("class Vehicle {\n var speed: Int = 0\n func accelerate() { "
@@ -13195,6 +13241,8 @@ SUITE(extraction) {
1319513241 RUN_TEST(csharp_interface);
1319613242 RUN_TEST(csharp_extension_block_members);
1319713243 RUN_TEST(csharp_constructor_of_type_named_extension);
13244+ RUN_TEST(csharp_constructor_of_escaped_type_named_extension);
13245+ RUN_TEST(csharp_extension_block_conditional_members);
1319813246 RUN_TEST(swift_class);
1319913247 RUN_TEST(swift_protocol);
1320013248 RUN_TEST(kotlin_function);
0 commit comments