-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VB Collection with ? gets an error #23928
Comments
@AnthonyDGreen Can you confirm the expected behavior for this? |
FYI: In C# it works as expected.
|
I tried to repo this with the code below. Can you see why this is different and/or let me know which version of VB and .NET you're having this issue with. Public Class Class1
Public Sub Foo()
Dim B As B = Nothing
Dim x = B.A?.Bar
For Each y In B.A?.Bar
Next
End Sub
End Class
Public Class B
Public A As A
End Class
Public Class A
Public Property Bar As IEnumerable(Of String)
End Class |
The question here is whether using System.Collections.Generic;
class C
{
void M(StructList? list)
{
foreach (var x in list) { }
}
}
struct StructList
{
public IEnumerator<int> GetEnumerator() => null;
} Imports System.Collections.Generic
Class C
Sub M(list As StructList?)
For Each x In list
Next
End Sub
End Class
Structure StructList
Public Function GetEnumerator() As IEnumerator(Of Integer)
Return Nothing
End Function
End Structure Indeed, the C# code compiles, while the VB code does not. Interestingly, the C# spec says that this code shouldn't compile, but Roslyn deliberately violates the spec: roslyn/src/Compilers/CSharp/Portable/Binder/ForEachLoopBinder.cs Lines 508 to 509 in a550ee1
I didn't check the VB spec, but I assume the behavior of the VB compiler is correct. So I think there is nothing to do here, unless you'd like to propose that VB changes its behavior (which would belong to the vblang repo) or that the C# spec should be changed to accommodate how the compiler currently behaves (which would belong to the csharplang repo). |
Closing as the compiler is behaving as designed for VB here. |
Version Used:
VS 2017 15.5.2
Steps to Reproduce:
Expected Behavior:
No Error
Actual Behavior:
Error BC32023 Expression is of type 'SyntaxList(Of AccessorDeclarationSyntax)?', which is not a collection type
The text was updated successfully, but these errors were encountered: