Browse Source

Avoid using operator + for string concatenation when ref-like types are involved.

pull/3243/head
Siegfried Pammer 10 months ago
parent
commit
fd1de09489
  1. 8
      ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs

8
ICSharpCode.Decompiler/CSharp/Transforms/ReplaceMethodCallsWithOperators.cs

@ -274,7 +274,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -274,7 +274,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
}
foreach (var arg in arguments)
{
if (arg.GetResolveResult() is InvocationResolveResult rr && IsStringConcat(rr.Member))
var rr = arg.GetResolveResult();
if (rr is InvocationResolveResult irr && IsStringConcat(irr.Member))
{
// Roslyn + mcs also flatten nested string.Concat() invocations within a operator+ use,
// which causes it to use the incorrect evaluation order despite the code using an
@ -282,6 +283,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -282,6 +283,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
// This problem is avoided if the outer call remains string.Concat() as well.
return false;
}
if (rr.Type.IsByRefLike)
{
// ref structs cannot be converted to object for use with +
return false;
}
}
// One of the first two arguments must be string, otherwise the + operator

Loading…
Cancel
Save