meetings/2024/LDM-2024-02-28.md
https://github.com/dotnet/csharplang/issues/5497
https://github.com/dotnet/csharplang/pull/7179/commits/520a2a40fc5a0fdb572e5f20f593f9eac59a88da
Today we looked over the proposed set of lookup rules for extensions. Much of the meeting was going over the rules as proposed, which I won't reiterate in these notes; they can be found in the linked pull request commit above. We made a few comments along the way:
this binds to; this for such scenarios is not the underlying type, it's the current extension type.static class Extensions
{
public static X ToX<Y>(this IEnumerable<Y> values) => ...
}
implicit extension ImmutableArrayExtensions<Y> for ImmutableArray<Y>
{
public X ToX() => ...
}
// or reverse:
static class Extensions
{
public static X ToX<Y>(this ImmutableArray<Y> values) => ...
}
implicit extension IEnumerableExtensions<Y> for IEnumerable<Y>
{
public X ToX() => ...
}
ToX methods to overload resolution and let it sort out which one is preferred, erroring if neither is
preferred. The precise details of this, and whether there will be any disambiguation of old vs new as a final tiebreaker, will need to come in a future meeting; what we are certain of at
this point is that the proposed version, where there is a preference of one version for lookup, isn't workable.class TableIDoNotOwn : IEnumerable<Item> { }
static class IEnumerableExtensions
{
public int Count<T>(this IEnumerable<T> t);
}
implicit extension MyTableExtensions for TableIDoNotOwn
{
public int Count { get { ... } }
}
// What happens here?
var v = table.Count; // Let's get a read from LDM
Lookup in extension types should treat the underlying type as if it is the base type of the extension type. We need to go back and redesign the rules for lookup of extension members from outside of an extension type to mix old and new style extensions.