From d07c91cba968e75cfd679ac0704327d388829f2e Mon Sep 17 00:00:00 2001 From: Jarvis-J-Jacob <287212888+Jarvis-J-Jacob@users.noreply.github.com> Date: Mon, 5 Oct 2026 13:51:53 +0530 Subject: [PATCH] test(csharp): assert bare this?.M() null-conditional call resolves #3976 made recv?.M() resolve through the receiver-typed path but only tested field receivers. Add a test that `this?.Save()` inside a class resolves to the enclosing class's Save() like `this.Save()`, and not to an unrelated class's Save(). Fixes #4077 (cherry picked from commit 6ce83480263f8041b17e027ac85789dc8f382a45) --- tests/test_csharp_member_calls.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_csharp_member_calls.py b/tests/test_csharp_member_calls.py index 96debbd1f..ba0090d53 100644 --- a/tests/test_csharp_member_calls.py +++ b/tests/test_csharp_member_calls.py @@ -320,6 +320,24 @@ def test_null_conditional_this_field_receiver_resolves(tmp_path): assert (commit, cache_save) not in calls +def test_null_conditional_bare_this_receiver_resolves(tmp_path): + """`this?.Save()` resolves like `this.Save()` (#4077).""" + calls, r = _calls(tmp_path, { + "S.cs": ( + "public class Other { public bool Save() => false; }\n" + "public class Repo {\n" + " public bool Save() => true;\n" + " public bool? Commit() { return this?.Save(); }\n" + "}\n" + ) + }) + commit = _find(r, ".Commit()", "commit") + repo_save = _find(r, ".Save()", "repo") + other_save = _find(r, ".Save()", "other") + assert (commit, repo_save) in calls, "this?.Save() must resolve like this.Save()" + assert (commit, other_save) not in calls + + def test_null_conditional_cross_file_receiver_resolves(tmp_path): calls, r = _calls(tmp_path, { "Server.cs": (