Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Suggested Nameof fix incorrectly suggests wrong type #594

Copy link
Copy link
@mirhagk

Description

@mirhagk
Issue body actions

The following code fragment

    public ActionResult ChangePassword(ChangePasswordMessageId? message, bool? Redirect = false)
    {
        var returnUrl = "ChangePassword";

Correctly identifies a place where nameof should be used. However it suggests using nameof(ChangePasswordMessageID) instead of the correct nameof(ChangePassword). If I change the type of message it produces the correct fix, and if I change returnUrl to "ChangePasswordMessage" then it does not suggest any fix. This leads me to believe that it's correctly identifying the issue, but incorrectly finding the suggested fix because of the matching prefix, although I haven't looked at the code so I can't be sure (I'll take a look later on if you want).

Tested with code-cracker version 1.0.0-rc2 (although I believe it also existed in earlier versions).

Here is a simple test that will not work:

public class TypeName
{
    void Foo(TypeName d)
    {
        var bar = new [] { "Foo" };
    }
}

And here is the test case:

        [Fact]
        public async Task ReplacesUsingMethodName()
        {
            const string source = @"
public class TypeName
{
    void Foo(TypeName d)
    {
        var bar = new [] { ""Foo"" };
    }
}";

            const string fixtest = @"
public class TypeName
{
    void Foo(TypeName d)
    {
        var bar = new [] { nameof(Foo) };
    }
}";
            await VerifyCSharpFixAsync(source, fixtest);
        }

@mirhagk is working on it.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.