[Fact]
public void Test()
{
string sourceA = """
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
[CollectionBuilder(typeof(MyCollectionBuilder), "Dummy")]
class MyCollection1 : IEnumerable<int>
{
IEnumerator<int> IEnumerable<int>.GetEnumerator() => throw null;
IEnumerator IEnumerable.GetEnumerator() => throw null;
}
class MyCollectionBuilder
{
}
class Program
{
static void Main()
{
MyCollection1 x = [1];
}
}
""";
CreateCompilation(
sourceA,
targetFramework: TargetFramework.Net80).VerifyEmitDiagnostics(
// (19,27): error CS9187: Could not find an accessible 'Dummy' method with the expected signature: a static method with a single parameter of type 'ReadOnlySpan<int>' and return type 'MyCollection1'.
// MyCollection1 x = [1];
Diagnostic(ErrorCode.ERR_CollectionBuilderAttributeMethodNotFound, "[1]").WithArguments("Dummy", "int", "MyCollection1").WithLocation(19, 27)
);
}
Expected:
An error at the application of a CollectionBuilder attribute about the fact that it doesn't point at the right place.
Expected: An error at the application of a CollectionBuilder attribute about the fact that it doesn't point at the right place.