Skip to content

Please explain when this warning gets issued more clearly #14231

Closed

Description

@binki

From reading this documentation, I would expect the following code to trigger this warning, but it doesn’t:

public class C {
    public void M(IThing thing) {
        var needUpdateVariable = thing.DoSomething();
    }
    public interface IThing {
        object DoSomething();
    }
}

Please add documentation explain what is different about that code and why it doesn’t throw this warning.

Thanks.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Activity

  1. Youssef1313 commented on Sep 6, 2019

    @Youssef1313
    Member

    A simpler example than yours is:

    static void Main(string[] args)
    {
        var x = 5; // Gives warning
        var y = Test(); // Doesn't give warning
    }
    
    private static int Test() => 5;

    It seems like the compiler doesn't give this warning when the value is a function call.
    I don't know if there is a specific reason for the compiler not to give the warning in that case or it's a bug in roslyn.

  2. Youssef1313 commented on Sep 6, 2019

    @Youssef1313
    Member
  3. Youssef1313 commented on Sep 6, 2019

    @Youssef1313
    Member

    This one is also related to that issue: dotnet/roslyn#15695

    I think that docs should be updated. I've opened a PR to update this article.

  4. added this to the September 2019 milestone on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions