-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Labels
Area-CompilersFeature - Extension EverythingThe extension everything featureThe extension everything featureFeature - Nullable Reference TypesNullable Reference TypesNullable Reference Types
Milestone
Description
Version Used:
Steps to Reproduce: .NET Lab
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
class Program
{
static void Main()
{
IEnumerable<string> items = [];
_ = new C()
{
Items = { items } // unexpected warning CS8620: Argument of type 'IEnumerable<string>' cannot be used for parameter 'list' of type 'List<string>' in 'Ext.extension<string>(List<string>)' due to differences in the nullability of reference types.
};
}
}
class C
{
public List<string> Items { get; set; } = [];
}
static class Ext
{
extension<T>(List<T> list)
{
public void Add(IEnumerable<T> values) => list.AddRange(values);
}
}Expected Behavior: No warnings are reported
Actual Behavior: A nullable warning is reported for 'items'. Note that the parameter which is being referenced is also unexpected,
The bug is may be related to the adjustments which are made to extension calls in order to include the receiver argument. We would want to ensure that the scenario behaves similarly to an classic public static void Add<T>(this List<T> list, IEnumerable<T> values) => ...; extension method.
Copilot
Metadata
Metadata
Assignees
Labels
Area-CompilersFeature - Extension EverythingThe extension everything featureThe extension everything featureFeature - Nullable Reference TypesNullable Reference TypesNullable Reference Types