VB Linq error on ToString()
- Dominant language
- No language data
- Stars
- 328
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
@lmkz commented on [Sun Dec 06 2015](https://github.com/dotnet/roslyn/issues/7266)
The following type of vb linq statement gives an error on the ToString() method call, which would be correct if multiple fields were being returned in the projection. Where there is only a single as in the case below, using ToString() should not be an error as it returns IEnumerable(of string).
```
Dim myThings = From anObj In Enumerable.Empty(Of Object)()
Select anObj.ToString()
```
---
@gafter commented on [Sun Dec 06 2015](https://github.com/dotnet/roslyn/issues/7266#issuecomment-162367044)
Aleksey, can you please evaluate if this is a bug or intended behavior? The error is
``` none
error BC36606: Range variable name cannot match the name of a member of the 'Object' class.
```
---
@AlekseyTs commented on [Mon Dec 07 2015](https://github.com/dotnet/roslyn/issues/7266#issuecomment-162623894)
This is an intended behavior, the rules do not depend on the amount of items within the Select clause.
---
@lmkz commented on [Mon Dec 07 2015](https://github.com/dotnet/roslyn/issues/7266#issuecomment-162638757)
This may be difficult to fix, but I think that error would be very confusing to someone who doesn't understand the underlying reason.
If this is valid:
```
Dim myThings = From anObj In Enumerable.Empty(Of Object)()
Select anObj.ToString().Substring(0)
```
Then this should be valid:
```
Dim myThings = From anObj In Enumerable.Empty(Of Object)()
Select anObj.ToString()
```
That error would also be very confusing to someone coming from c# where the above statement would compile fine (substituting var for dim)
---
@gafter commented on [Mon Dec 07 2015](https://github.com/dotnet/roslyn/issues/7266#issuecomment-162653480)
@lmkz OK, we'll refile it as a language issue, as it would have to be fixed in the spec before we would make a compiler change.
---
@AnthonyDGreen commented on [Tue Feb 02 2016](https://github.com/dotnet/roslyn/issues/7266#issuecomment-178877921)
Hi @lmkz,
Thanks for raising this. We actually discussed this case in the Visual Basic language design meeting several years ago. While it's technically "correct" it's confusing in a very simple scenario. You're definitely not the first person hit this--I've been bitten by a few times myself. We had a proposal fix it for the last version of VB but we ran out of time. Hopefully we'll get to it this time around.
The proposal was more or less as you described though I do recall an open question of whether this should apply to just collisions in Select clauses or all name collisions.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.