dotnet / dotnet/fsharp

`GetDeclaredItems` returns wrong symbol inside non-recursive declaration

Open
#7,694 5 comments 2 reactions 0 assignees View on GitHub
Area-LangService-AutoComplete Bug Impact-Medium
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Consider the following code:
```fsharp
module Module

let id =
{caret}id
```
When trying to get a symbol for `id` at the caret location using `GetSymbolUseAtLocation` it's expected to get `FSharp.Core.Operators.Id` result since `Module.id` is not recursive, however `Module.id` is returned.

It works this way due to the following: `GetDeclaredItems` takes known name resolution environments at the requested range (`GetBestEnvForPos`) and tries to resolve requested qualified identifier using the best possible one.

It works properly during type-check itself: when the right hand expression is being type-checked the new `id` is not yet present in the environment, thus, the `id` reference expression is resolved to the existing `id`. After the successful check the new `id` is added to the environment making the existing one shadowed. Since the same environment is later used by `GetDeclaredItems` at the range we get the new `id` instead of the FSharp.Core one. It's used in FCS features like getting completion lookup items which all get the wrong symbol.

Screenshot 2019-10-03 at 22 27 59

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.