Skip to content

Use of nameof changes name resolution rules #8661

Closed

Description

@auduchinok

It seems using nameof makes symbol resolved using type name resolution rules first.

let f (obj: obj) =
    nameof obj

In this example obj inside the function is resolved to type, which is unexpected, making local obj value unused:

Screenshot 2020-03-05 at 16 58 35

Without nameof it works as expected:

Screenshot 2020-03-05 at 17 07 17

When there's no matching type to resolve to is found, it also works as expected:

Screenshot 2020-03-05 at 16 58 44

Activity

  1. added this to the Backlog milestone on Mar 5, 2020
  2. cartermp commented on Mar 5, 2020

    @cartermp
    Contributor

    @dsyme @TIHan we'll want to look at this one in the next sprint I think, especially if we can focus on finishing up some design concerns around nameof

  3. abelbraaksma commented on Mar 5, 2020

    @abelbraaksma
    Contributor

    But is it really an issue in practice? nameOf works on types as well as identifiers. And obj as variable is still accessible, and the returned string should be "obj" in either case; alternatively one might consider the ambiguity an error, after all, there's no way to know whether the user intended one over the other.

  4. auduchinok commented on Mar 5, 2020

    @auduchinok
    MemberAuthor

    But is it really an issue in practice?

    It can be. This is a close to minimal repro which doesn't look too bad on its own indeed. But it clearly shows a different behavior which, together with a more subtle names clash, can make features like Rename refactoring work very wrong.

  5. abelbraaksma commented on Mar 5, 2020

    @abelbraaksma
    Contributor

    can make features like Rename refactoring work very wrong.

    Didn't think of that, good point.

  6. dsyme commented on Jul 23, 2020

    @dsyme
    Contributor

    Thanks for this bug report

  7. dsyme commented on Jul 27, 2020

    @dsyme
    Contributor

    Thanks again for this report, I made the appropriate fix and update to the RFC, see fsharp/fslang-design#488

  8. dsyme commented on Jul 27, 2020

    @dsyme
    Contributor

    I'll close this report as it is now part of the RFC update at #8754

  9. removed this from the Backlog milestone on Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions