Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calls with nullable warning suppressions cannot be intercepted #70061

Closed
TessenR opened this issue Sep 21, 2023 · 0 comments · Fixed by #70120
Closed

Calls with nullable warning suppressions cannot be intercepted #70061

TessenR opened this issue Sep 21, 2023 · 0 comments · Fixed by #70120
Assignees
Milestone

Comments

@TessenR
Copy link

TessenR commented Sep 21, 2023

Version Used:

Microsoft Visual Studio Professional 2022
Version 17.7.4
VisualStudio.17.Release/17.7.4+34031.279
Microsoft .NET Framework
Version 4.8.09037

Steps to Reproduce:

Compile the following code:

using System;
using System.Runtime.CompilerServices;

Action? a = null;
a!();
a();

static class InterceptorMethods
{
  [InterceptsLocation("Program.cs", line: 5, character: 1)]
  [InterceptsLocation("Program.cs", line: 6, character: 1)]
  public static void Intercept(this Action a) { }
}

namespace System.Runtime.CompilerServices
{
  [AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
  public class InterceptsLocationAttribute : System.Attribute
  {
    public InterceptsLocationAttribute(string path, int line, int character) { }
  }
}

Expected Behavior:
Either you can intercept both delegate invocations or neither of them.

Actual Behavior:
Error CS9151: Possible method name 'a' cannot be intercepted because it is not being invoked. is reported for an interceptor that attempts to intercept the call with a nullable warning suppression expression.

It seems that it's completely impossible to intercept the call with a nullable warning suppression as you just get different errors when attempt to change the interception character e.g. to the argument list start offset.
It'd be rather strange for a feature to be incompatible with NRT as you might accidentally break behavior just be suppressing a spurious warning.

Relates to test plan #67421

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 21, 2023
@jcouv jcouv added this to the 17.8 milestone Sep 25, 2023
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants