Fsharp: Use of nameof changes name resolution rules

Created on 5 Mar 2020  路  7Comments  路  Source: dotnet/fsharp

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

Area-Compiler Resolution-Duplicate bug

Most helpful comment

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.

All 7 comments

@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

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.

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.

can make features like Rename refactoring work very wrong.

Didn't think of that, good point.

Thanks for this bug report

Thanks again for this report, I made the appropriate fix and update to the RFC, see https://github.com/fsharp/fslang-design/pull/488

I'll close this report as it is now part of the RFC update at https://github.com/dotnet/fsharp/pull/8754

Was this page helpful?
0 / 5 - 0 ratings