Open AdamSpeight2008 opened 3 years ago
Thanks @AdamSpeight2008
And it is also OK if we use the lambda form. This gives no error:
Dim Length = "asdf".Select(Function(s As String) s.Length)
Note: I can't really tell when an issue belong to the lang, or Roslyn. I thought that this error originated from VB compiler, not something related to the editor and Roslyn.
C# doesn't have this issue. This works fine:
var Length = from s in new string[]{"asdf"}
select s.Length;
I thought that this error originated from VB compiler, not something related to the editor and Roslyn.
Roslyn is the VB compiler.
Note the code works as expected in VS2017
May be it is more recent. I never faced this before. This is another case involving method params:
Sub Foo(x As Integer, y As Integer)
' No issue
Dim r = From n In {1, 2, 3}
Select New With {.x = 1, .y = 2}
' ' No issue
r = From p In {New Point(10, 20)}
Select New With {.x = p.X, .y = p.Y}
' Issues in p.X and p.Y
r = From p In {New Point(10, 20)}
Select p.X, p.Y
End Sub
Obviously, it is related to implicit anonymous type defined in the select, and the workaround is to explicitly define the anonymous type.
Note the code works as expected in VS2017
This means they missed a test for this case, and should create it with the fix.
I think i've seen the cause, but I can't find it now. One of the lookup option / result options changed.
@CyrusNajmabadi
Issue seem to be related to forming the Select
part of the query, as Let
works find.
Same issue as https://github.com/dotnet/roslyn/issues/15779?
@tmat Based on your comment in the issue above, I think you saw a reason why the program was invalid (I couldn't see that reason). Can you have a look on whether that reason applies to the code in this issue?
@Youssef1313 It is the same issue as #15779. the variable named b
is a different b
to one being qualified as a member access on pair.b
. So as we understand it, there is no shadowing,
The reason the I can't find the possible issue, is that if I recall correctly the affected line (and it's a single line) that it is in a kind of unrelated change (according to the pull request). Pull Request is something relatively minor like spelling error, or variable name change.
Think this was the pull request where the option changed.
Original Discoverer @VBAndCs in Link To Original Post
Steps to Reproduce:
Any code where the name of the variable (being assigned to), with the assignment expression having a property / method with the same name.
Example.
Dim Length = From s In {"asdf"} Select s.Length
Actual Behavior
The following example works,
Dim Length = "asdf".Length
Which narrows to suspects to LINQ Queries.
Expected Behavior: The name to be correctly resolved, as the
Length
is being qualified by thes