Browse Source

Add `OutVarResolveResult` to overload resolution (not yet used by CallBuilder)

pull/2145/head
Daniel Grunwald 5 years ago
parent
commit
7f915ad035
  1. 24
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs
  2. 10
      ICSharpCode.Decompiler/CSharp/Resolver/OverloadResolution.cs
  3. 1
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  4. 31
      ICSharpCode.Decompiler/Semantics/OutVarResolveResult.cs

24
ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs

@ -34,6 +34,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -34,6 +34,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
TestIndexer();
Issue1281();
Issue1747();
CallAmbiguousOutParam();
}
#region ConstructorTest
@ -246,6 +247,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -246,6 +247,29 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
obj[5] = null;
}
#endregion
#region Out Parameter
static void AmbiguousOutParam(out string a)
{
a = null;
Console.WriteLine("AmbiguousOutParam(out string)");
}
static void AmbiguousOutParam(out int b)
{
b = 1;
Console.WriteLine("AmbiguousOutParam(out int)");
}
static void CallAmbiguousOutParam()
{
Console.WriteLine("CallAmbiguousOutParam:");
string a;
int b;
AmbiguousOutParam(out a);
AmbiguousOutParam(out b);
}
#endregion
}
class IndexerTests

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

@ -649,12 +649,18 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -649,12 +649,18 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
continue;
}
ByReferenceResolveResult brrr = arguments[i] as ByReferenceResolveResult;
if (brrr != null)
if (arguments[i] is ByReferenceResolveResult brrr)
{
if (brrr.ReferenceKind != candidate.Parameters[parameterIndex].ReferenceKind)
candidate.AddError(OverloadResolutionErrors.ParameterPassingModeMismatch);
}
else if (arguments[i] is OutVarResolveResult)
{
if (candidate.Parameters[parameterIndex].ReferenceKind != ReferenceKind.Out)
candidate.AddError(OverloadResolutionErrors.ParameterPassingModeMismatch);
// 'out var decl' arguments are compatible with any out parameter
continue;
}
else
{
if (candidate.Parameters[parameterIndex].ReferenceKind != ReferenceKind.None)

1
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -86,6 +86,7 @@ @@ -86,6 +86,7 @@
<Compile Include="Documentation\XmlDocumentationElement.cs" />
<Compile Include="IL\ControlFlow\AwaitInFinallyTransform.cs" />
<Compile Include="IL\Transforms\IntroduceNativeIntTypeOnLocals.cs" />
<Compile Include="Semantics\OutVarResolveResult.cs" />
<Compile Include="Solution\ProjectId.cs" />
<Compile Include="Solution\ProjectItem.cs" />
<Compile Include="Solution\SolutionCreator.cs" />

31
ICSharpCode.Decompiler/Semantics/OutVarResolveResult.cs

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
// Copyright (c) 2020 Daniel Grunwald
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.Decompiler.Semantics
{
/// <summary>
/// Represents the implicitly-typed "out var".
/// Special-cased in overload resolution to be compatible with any out-parameter.
/// </summary>
class OutVarResolveResult : ResolveResult
{
public OutVarResolveResult() : base(SpecialType.NoType) { }
}
}
Loading…
Cancel
Save