Skip to content
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

Knock out BC31902 #602

Open
jhudsoncedaron opened this issue May 6, 2021 · 0 comments
Open

Knock out BC31902 #602

jhudsoncedaron opened this issue May 6, 2021 · 0 comments

Comments

@jhudsoncedaron
Copy link

Imports System.Runtime.CompilerServices

Public Module Program
    <Extension>
    Public Sub AddRange(Of T)([Me] As IList(Of T), <[ParamArray]> elements As IEnumerable(Of T))
	For Each e In elements
		[Me].Add(e)
	Next
    End Sub

    <Extension>
    Public Sub AddRange(Of T)([Me] As List(Of T), <[ParamArray]> elements As T())
	For Each e In elements
		[Me].Add(e)
	Next
    End Sub

    Public Sub Main(args As String())
	Dim l As IList(Of Integer) = New List(Of Integer)
        l.AddRange(New Integer(){1,2,3})
    End Sub
End Module

Raises BC31902

What's going on here is this library is written in VB specifically to spoof-out the C# compiler to allow params IEnumerable<T> to work (and a few other things C# should be able to do but can't but that's for another day). But in further development I found it necessary to call the methods within the implementation and it got kicked out.

The simplest solution is not to treat it as a params argument if it's not an array type, and given the existing error this breaks no code.

@jaredpar jaredpar transferred this issue from dotnet/roslyn Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant