Browse Source

Extract implicit-span-conversion-related logic in HandleImplicitConversion into separate method.

pull/3930/head
Daniel Grunwald 1 month ago committed by Christoph Wille
parent
commit
67ef999992
  1. 1
      .gitattributes
  2. 21
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs

1
.gitattributes vendored

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
*.cs text eol=crlf diff=csharp
*.sln text eol=crlf
*.csproj text eol=crlf
*.resx text eol=crlf
# Consumed verbatim by Linux tools (shell-executed rpm spec, dpkg control, desktop entry);
# CRLF breaks them, so keep them LF even in Windows working trees.
*.spec text eol=lf

21
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -353,6 +353,22 @@ namespace ICSharpCode.Decompiler.CSharp @@ -353,6 +353,22 @@ namespace ICSharpCode.Decompiler.CSharp
&& method.Parameters[0].Type.IsKnownType(KnownTypeCode.ReadOnlySpanOfT);
}
// Gets whether a call to `method` is equivalent to an implicit span conversion.
static bool IsEquivalentToSpanConversion(IMethod method)
{
if (method.DeclaringType.IsKnownType(KnownTypeCode.SpanOfT)
|| method.DeclaringType.IsKnownType(KnownTypeCode.ReadOnlySpanOfT))
{
if (method.IsOperator
&& method.Name == "op_Implicit")
{
return true;
}
}
return IsStringToReadOnlySpanCharAsSpan(method)
|| IsReadOnlySpanCastUp(method);
}
public ExpressionWithResolveResult Build(OpCode callOpCode, IMethod method,
IReadOnlyList<ILInstruction> callArguments,
IReadOnlyList<int>? argumentToParameterMap = null,
@ -1587,13 +1603,10 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1587,13 +1603,10 @@ namespace ICSharpCode.Decompiler.CSharp
// own members, so such a call is the conversion and folding it back is exact. Any
// other method reaching this point is a user-defined conversion operator, which only
// the user-defined conversion resolving to that very operator may be folded into.
bool spanConversionMember = method.DeclaringType.IsKnownType(KnownTypeCode.SpanOfT)
|| method.DeclaringType.IsKnownType(KnownTypeCode.ReadOnlySpanOfT)
|| IsStringToReadOnlySpanCharAsSpan(method);
bool directlyConvertible = conv.IsValid
&& (conv.IsUserDefined
? conv.Method.Equals(method, NormalizeTypeVisitor.TypeErasure)
: conv.IsImplicitSpanConversion && spanConversionMember);
: conv.IsImplicitSpanConversion && IsEquivalentToSpanConversion(method));
if (!directlyConvertible)
{
// implicit conversion to targetType isn't directly possible, so first insert a cast to the argument type

Loading…
Cancel
Save