Skip to content

Commit dcb37f7

Browse files
author
Hertzole
authored
Merge branch 'master' into toggle-smooth-scrolling
2 parents 1379d9f + fb2561a commit dcb37f7

File tree

16 files changed

+155
-56
lines changed

16 files changed

+155
-56
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
2828
<PackageVersion Include="Microsoft.NETCore.ILAsm" Version="9.0.0" />
2929
<PackageVersion Include="Microsoft.NETCore.ILDAsm" Version="9.0.0" />
30-
<PackageVersion Include="Microsoft.Sbom.Targets" Version="3.0.1" />
30+
<PackageVersion Include="Microsoft.Sbom.Targets" Version="3.0.1" />
3131
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
3232
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
3333
<PackageVersion Include="Mono.Cecil" Version="0.11.6" />
@@ -46,7 +46,7 @@
4646
<PackageVersion Include="System.Resources.Extensions" Version="9.0.1" />
4747
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
4848
<PackageVersion Include="TomsToolbox.Composition.MicrosoftExtensions" Version="2.22.0" />
49-
<PackageVersion Include="TomsToolbox.Wpf.Composition" Version="2.20.0" />
49+
<PackageVersion Include="TomsToolbox.Wpf.Composition" Version="2.22.0" />
5050
<PackageVersion Include="TomsToolbox.Wpf.Composition.AttributedModel" Version="2.22.0" />
5151
<PackageVersion Include="TomsToolbox.Wpf.Styles" Version="2.22.0" />
5252
<PackageVersion Include="coverlet.collector" Version="6.0.3" />

ICSharpCode.Decompiler.Tests/Helpers/Tester.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21-
using System.Diagnostics;
2221
using System.IO;
2322
using System.Linq;
2423
using System.Reflection.PortableExecutable;
@@ -330,6 +329,45 @@ static string GetTargetFrameworkAttributeSnippetFile()
330329
return tempFile;
331330
}
332331

332+
const string nonEmbeddedAttributesSnippet = @"
333+
using System;
334+
335+
#if !NET60
336+
namespace System.Runtime.CompilerServices
337+
{
338+
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
339+
internal sealed class CompilerFeatureRequiredAttribute : Attribute
340+
{
341+
public CompilerFeatureRequiredAttribute(string featureName)
342+
{
343+
}
344+
}
345+
346+
internal class IsExternalInit
347+
{
348+
}
349+
#endif
350+
#if !NET70
351+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
352+
internal sealed class RequiredMemberAttribute : Attribute
353+
{
354+
}
355+
#endif
356+
#if !NET60
357+
}
358+
#endif
359+
";
360+
361+
static readonly Lazy<string> nonEmbeddedAttributesSnippetFile = new Lazy<string>(GetNonEmbeddedAttributesSnippetFile);
362+
363+
static string GetNonEmbeddedAttributesSnippetFile()
364+
{
365+
// Note: this leaks a temporary file, we're not attempting to delete it, because it is only one.
366+
var tempFile = Path.GetTempFileName();
367+
File.WriteAllText(tempFile, nonEmbeddedAttributesSnippet);
368+
return tempFile;
369+
}
370+
333371
public static List<string> GetPreprocessorSymbols(CompilerOptions flags)
334372
{
335373
var preprocessorSymbols = new List<string>();
@@ -419,6 +457,11 @@ public static async Task<CompilerResults> CompileCSharp(string sourceFileName, C
419457
sourceFileNames.Add(targetFrameworkAttributeSnippetFile.Value);
420458
}
421459

460+
if (targetNet40)
461+
{
462+
sourceFileNames.Add(nonEmbeddedAttributesSnippetFile.Value);
463+
}
464+
422465
var preprocessorSymbols = GetPreprocessorSymbols(flags);
423466

424467
if ((flags & CompilerOptions.UseMcsMask) == 0)

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
131131
<Compile Include="TestAssemblyResolver.cs" />
132132
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />
133+
<Compile Include="TestCases\Pretty\Comparisons.cs" />
133134
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
134135
<Compile Include="TestCases\VBPretty\VBAutomaticEvents.cs" />
135136
<Compile Include="TestCases\VBPretty\VBNonGenericForEach.cs" />
@@ -151,7 +152,7 @@
151152
<None Include="TestCases\Pretty\CovariantReturns.cs" />
152153
<Compile Include="TestCases\VBPretty\VBPropertiesTest.cs" />
153154
<None Include="TestCases\ILPretty\Issue2260SwitchString.cs" />
154-
<None Include="TestCases\Pretty\Records.cs" />
155+
<Compile Include="TestCases\Pretty\Records.cs" />
155156
<Compile Include="TestCases\VBPretty\Issue2192.cs" />
156157
<Compile Include="Util\FileUtilityTests.cs" />
157158
<Compile Include="TestCases\Pretty\FunctionPointers.cs" />

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ public async Task OptionalArguments([ValueSource(nameof(defaultOptions))] Compil
586586
await RunForLibrary(cscOptions: cscOptions);
587587
}
588588

589+
[Test]
590+
public async Task Comparisons([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
591+
{
592+
await RunForLibrary(cscOptions: cscOptions);
593+
}
594+
589595
[Test]
590596
public async Task ConstantsTests([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
591597
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
2+
{
3+
public class Comparisons
4+
{
5+
private class A
6+
{
7+
}
8+
9+
private class B
10+
{
11+
}
12+
13+
private bool CompareUnrelatedNeedsCast(A a, B b)
14+
{
15+
return (object)a == b;
16+
}
17+
}
18+
}

ICSharpCode.Decompiler.Tests/TestCases/Pretty/InitializerTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,19 @@ public interface IData
235235
{
236236
int Property { get; set; }
237237
}
238+
239+
#if CS90
240+
public class Issue3392Type
241+
{
242+
public bool Flag { get; init; }
243+
public List<int> List { get; } = new List<int>();
244+
245+
public Issue3392Type(object x)
246+
{
247+
248+
}
249+
}
250+
#endif
238251
#endregion
239252

240253
private S s1;
@@ -1010,6 +1023,17 @@ public OtherItem2 Issue1345b()
10101023
otherItem.Data2.Nullable = 3m;
10111024
return otherItem;
10121025
}
1026+
1027+
#if CS90
1028+
public Issue3392Type Issue3392(Issue3392Type x)
1029+
{
1030+
x = new Issue3392Type(null) {
1031+
Flag = false
1032+
};
1033+
x.List.AddRange(Enumerable.Range(0, 10));
1034+
return x;
1035+
}
1036+
#endif
10131037
#if CS60
10141038
public OtherItem2 Issue1345c()
10151039
{

ICSharpCode.Decompiler.Tests/TestCases/Pretty/OptionalArguments.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,28 @@ public enum MyEnum
3232
B
3333
}
3434

35+
internal class OptionalArgumentTest
36+
{
37+
private static void Test()
38+
{
39+
Test2();
40+
Test3();
41+
Test4();
42+
}
43+
44+
private static void Test2(int a = 0)
45+
{
46+
}
47+
48+
private static void Test3(int a = 0, int? b = null)
49+
{
50+
}
51+
52+
private static void Test4(int? b = null, int a = 0)
53+
{
54+
}
55+
}
56+
3557
public OptionalArguments(string name, int a = 5)
3658
{
3759

ICSharpCode.Decompiler.Tests/TestCases/Pretty/Records.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public record Pair<A, B>
4444
public record PairWithPrimaryCtor<A, B>(A First, B Second);
4545

4646
public record PrimaryCtor(int A, string B);
47-
public record PrimaryCtorWithAttribute([RecordTest("param")] [property: RecordTest("property")][field: RecordTest("field")] int a);
47+
public record PrimaryCtorWithAttribute([RecordTest("param")][property: RecordTest("property")][field: RecordTest("field")] int a);
4848
public record PrimaryCtorWithField(int A, string B)
4949
{
5050
public double C = 1.0;
@@ -169,7 +169,7 @@ public record struct Pair<A, B>
169169
public record struct PairWithPrimaryCtor<A, B>(A First, B Second);
170170

171171
public record struct PrimaryCtor(int A, string B);
172-
public record struct PrimaryCtorWithAttribute([RecordTest("param")] [property: RecordTest("property")][field: RecordTest("field")] int a);
172+
public record struct PrimaryCtorWithAttribute([RecordTest("param")][property: RecordTest("property")][field: RecordTest("field")] int a);
173173
public record struct PrimaryCtorWithField(int A, string B)
174174
{
175175
public double C = 1.0;
@@ -242,27 +242,3 @@ public record struct WithRequiredMembers
242242
}
243243
#endif
244244
}
245-
#if !NET60
246-
namespace System.Runtime.CompilerServices
247-
{
248-
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
249-
internal sealed class CompilerFeatureRequiredAttribute : Attribute
250-
{
251-
public CompilerFeatureRequiredAttribute(string featureName)
252-
{
253-
}
254-
}
255-
256-
internal class IsExternalInit
257-
{
258-
}
259-
#endif
260-
#if !NET70
261-
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
262-
internal sealed class RequiredMemberAttribute : Attribute
263-
{
264-
}
265-
#endif
266-
#if !NET60
267-
}
268-
#endif

ICSharpCode.Decompiler.Tests/TestCases/Pretty/Structs.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,4 @@ public struct StructWithRequiredMembers
5959
public required string LastName { get; set; }
6060
}
6161
#endif
62-
}
63-
64-
namespace System.Runtime.CompilerServices
65-
{
66-
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
67-
internal sealed class CompilerFeatureRequiredAttribute : Attribute
68-
{
69-
public CompilerFeatureRequiredAttribute(string featureName)
70-
{
71-
}
72-
}
73-
74-
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
75-
internal sealed class RequiredMemberAttribute : Attribute
76-
{
77-
}
78-
}
62+
}

ICSharpCode.Decompiler/CSharp/CallBuilder.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,10 @@ bool CheckArgument(out int len, out IType t)
10431043

10441044
bool IsOptionalArgument(IParameter parameter, TranslatedExpression arg)
10451045
{
1046-
if (!parameter.IsOptional || !arg.ResolveResult.IsCompileTimeConstant)
1046+
if (!parameter.IsOptional)
1047+
return false;
1048+
1049+
if (!arg.ResolveResult.IsCompileTimeConstant && arg.ResolveResult is not ConversionResolveResult { Conversion.IsNullLiteralConversion: true })
10471050
return false;
10481051
if (parameter.GetAttributes().Any(a => a.AttributeType.IsKnownType(KnownAttribute.CallerMemberName)
10491052
|| a.AttributeType.IsKnownType(KnownAttribute.CallerFilePath)

0 commit comments

Comments
 (0)