Replies: 2 comments 5 replies
-
This would be a huge breaking change. ref structs in Expression<Func<string[], string, bool>> expr =
(x, y) => Foo.Contains(x, y);
Console.WriteLine(expr.Compile()(["hello", "world"], "hello")); // prints True under CoreCLR
class Foo
{
internal static bool Contains(ReadOnlySpan<string> ss, string s) => ss.Contains(s);
} I don't see any reason for regressing such valid scenarios in CoreCLR just because someone suddenly wants to use IMO we should keep it as is, and fix dotnet/runtime#45152 and dotnet/runtime#96160 instead. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
Ignore overloads with
ref struct
parameters when binding withinExpression
lambdas.Motivation
C#13 adds support for
params
span, and C# preview adds first-class span types. Both of these features allow overload resolution to prefer overloads with span type parameters in more cases than with earlier language versions.However, within an
Expression
, binding to a member that requires aref struct
instance may result in a compile-time or runtime error, and is therefore a breaking change.Example 1:
params
span, see #110592Example 2: First-class span types, see #109757
Design
12.6.4.2 Applicable function member could be updated as follows:
Note that the disqualifying parameter:
params
parameterallows ref struct
Drawbacks
Ignoring certain overloads may be a breaking change itself, in limited scenarios where
ref struct
instances are supported within anExpression
currently. Examples?Alternatives
No compiler change; add IDE fixer
Make no additional compiler changes. Instead, require callers to rewrite
Expression
instances to work around the overload resolution changes. An IDE fixer could be provided to rewrite calls for these cases.Support
ref struct
arguments withinExpression
lambdasThe
Expression
interpreter relies on reflection, so supporting these cases would require supportingref struct
arguments in reflection or rewriting parts of the interpreter.Design meetings
Beta Was this translation helpful? Give feedback.
All reactions