Browse Source

Handle ReferenceKind.RefReadOnly in a few more cases

pull/3243/head
Siegfried Pammer 11 months ago
parent
commit
e6004e5f26
  1. 3
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  2. 4
      ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs
  3. 3
      ICSharpCode.Decompiler/Semantics/ByReferenceResolveResult.cs
  4. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs

3
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -134,8 +134,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
if (!useImplicitlyTypedOut) if (!useImplicitlyTypedOut)
return expression; return expression;
if (expression.GetResolveResult() is ByReferenceResolveResult brrr if (expression.GetResolveResult() is ByReferenceResolveResult { ReferenceKind: ReferenceKind.Out } brrr)
&& brrr.IsOut)
{ {
expression.AddAnnotation(UseImplicitlyTypedOutAnnotation.Instance); expression.AddAnnotation(UseImplicitlyTypedOutAnnotation.Instance);
} }

4
ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs

@ -671,8 +671,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
{ {
// AllowImplicitIn: `in` parameters can be filled implicitly without `in` DirectionExpression // AllowImplicitIn: `in` parameters can be filled implicitly without `in` DirectionExpression
// IsExtensionMethodInvocation: `this ref` and `this in` parameters can be filled implicitly // IsExtensionMethodInvocation: `this ref` and `this in` parameters can be filled implicitly
if (((paramRefKind == ReferenceKind.In && AllowImplicitIn) if (((paramRefKind is ReferenceKind.In or ReferenceKind.RefReadOnly && AllowImplicitIn)
|| (IsExtensionMethodInvocation && parameterIndex == 0 && (paramRefKind == ReferenceKind.In || paramRefKind == ReferenceKind.Ref)) || (IsExtensionMethodInvocation && parameterIndex == 0 && (paramRefKind is ReferenceKind.In or ReferenceKind.Ref or ReferenceKind.RefReadOnly))
) && candidate.ParameterTypes[parameterIndex].SkipModifiers() is ByReferenceType brt) ) && candidate.ParameterTypes[parameterIndex].SkipModifiers() is ByReferenceType brt)
{ {
// Treat the parameter as if it was not declared "in" for the following steps // Treat the parameter as if it was not declared "in" for the following steps

3
ICSharpCode.Decompiler/Semantics/ByReferenceResolveResult.cs

@ -30,9 +30,6 @@ namespace ICSharpCode.Decompiler.Semantics
public class ByReferenceResolveResult : ResolveResult public class ByReferenceResolveResult : ResolveResult
{ {
public ReferenceKind ReferenceKind { get; } public ReferenceKind ReferenceKind { get; }
public bool IsOut => ReferenceKind == ReferenceKind.Out;
public bool IsRef => ReferenceKind == ReferenceKind.Ref;
public bool IsIn => ReferenceKind == ReferenceKind.In;
public readonly ResolveResult ElementResult; public readonly ResolveResult ElementResult;

2
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs

@ -63,7 +63,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var metadata = module.metadata; var metadata = module.metadata;
var parameter = metadata.GetParameter(handle); var parameter = metadata.GetParameter(handle);
bool defaultValueAssignmentAllowed = ReferenceKind is ReferenceKind.None or ReferenceKind.In; bool defaultValueAssignmentAllowed = ReferenceKind is ReferenceKind.None or ReferenceKind.In or ReferenceKind.RefReadOnly;
if (IsOptional && (!defaultValueAssignmentAllowed || !HasConstantValueInSignature)) if (IsOptional && (!defaultValueAssignmentAllowed || !HasConstantValueInSignature))
{ {

Loading…
Cancel
Save