Skip to content

Commit 4887de3

Browse files
Merge
2 parents c220f06 + f5e8512 commit 4887de3

File tree

95 files changed

+1734
-612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1734
-612
lines changed

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
persist-credentials: false
3030

3131
- name: "Run analysis"
32-
uses: ossf/[email protected].0 # https://github.com/marketplace/actions/ossf-scorecard-action
32+
uses: ossf/[email protected].1 # https://github.com/marketplace/actions/ossf-scorecard-action
3333
with:
3434
results_file: results.sarif
3535
results_format: sarif

Directory.Packages.props

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<PackageVersion Include="K4os.Compression.LZ4" Version="1.3.8" />
1616
<PackageVersion Include="McMaster.Extensions.CommandLineUtils" Version="4.1.1" />
1717
<PackageVersion Include="McMaster.Extensions.Hosting.CommandLine" Version="4.1.1" />
18-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
19-
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.12.0" />
18+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
19+
<PackageVersion Include="Microsoft.CodeAnalysis.VisualBasic" Version="4.13.0" />
2020
<PackageVersion Include="Microsoft.DiaSymReader.Converter.Xml" Version="1.1.0-beta2-22171-02" />
2121
<PackageVersion Include="Microsoft.DiaSymReader" Version="1.4.0" />
2222
<PackageVersion Include="Microsoft.DiaSymReader.Native" Version="17.0.0-beta1.21524.1" />
@@ -45,11 +45,11 @@
4545
<PackageVersion Include="System.Reflection.Metadata" Version="9.0.1" />
4646
<PackageVersion Include="System.Resources.Extensions" Version="9.0.1" />
4747
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
48-
<PackageVersion Include="TomsToolbox.Composition.MicrosoftExtensions" Version="2.21.0" />
49-
<PackageVersion Include="TomsToolbox.Wpf.Composition" Version="2.20.0" />
50-
<PackageVersion Include="TomsToolbox.Wpf.Composition.AttributedModel" Version="2.21.0" />
51-
<PackageVersion Include="TomsToolbox.Wpf.Styles" Version="2.21.0" />
52-
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
48+
<PackageVersion Include="TomsToolbox.Composition.MicrosoftExtensions" Version="2.22.0" />
49+
<PackageVersion Include="TomsToolbox.Wpf.Composition" Version="2.22.0" />
50+
<PackageVersion Include="TomsToolbox.Wpf.Composition.AttributedModel" Version="2.22.0" />
51+
<PackageVersion Include="TomsToolbox.Wpf.Styles" Version="2.22.0" />
52+
<PackageVersion Include="coverlet.collector" Version="6.0.3" />
5353
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
5454
<PackageVersion Include="System.Private.Uri" Version="4.3.2" />
5555
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<None Include="TestCases\ILPretty\Issue1922.il" />
108108
<None Include="TestCases\ILPretty\Issue1918.il" />
109109
<None Include="TestCases\ILPretty\Issue2104.il" />
110+
<None Include="TestCases\ILPretty\Issue3421.il" />
110111
<None Include="TestCases\ILPretty\WeirdEnums.il" />
111112
<None Include="TestCases\ILPretty\ConstantBlobs.il" />
112113
<None Include="TestCases\ILPretty\CS1xSwitch_Debug.il" />
@@ -132,7 +133,9 @@
132133
<Compile Include="Output\InsertParenthesesVisitorTests.cs" />
133134
<Compile Include="ProjectDecompiler\TargetFrameworkTests.cs" />
134135
<Compile Include="TestAssemblyResolver.cs" />
136+
<Compile Include="TestCases\ILPretty\Issue3421.cs" />
135137
<Compile Include="TestCases\ILPretty\MonoFixed.cs" />
138+
<Compile Include="TestCases\Pretty\Comparisons.cs" />
136139
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
137140
<Compile Include="TestCases\VBPretty\VBAutomaticEvents.cs" />
138141
<Compile Include="TestCases\VBPretty\VBNonGenericForEach.cs" />
@@ -154,7 +157,7 @@
154157
<None Include="TestCases\Pretty\CovariantReturns.cs" />
155158
<Compile Include="TestCases\VBPretty\VBPropertiesTest.cs" />
156159
<None Include="TestCases\ILPretty\Issue2260SwitchString.cs" />
157-
<None Include="TestCases\Pretty\Records.cs" />
160+
<Compile Include="TestCases\Pretty\Records.cs" />
158161
<Compile Include="TestCases\VBPretty\Issue2192.cs" />
159162
<Compile Include="Util\FileUtilityTests.cs" />
160163
<Compile Include="TestCases\Pretty\FunctionPointers.cs" />

ICSharpCode.Decompiler.Tests/ILPrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ public async Task Issue2443()
207207
await Run();
208208
}
209209

210+
[Test]
211+
public async Task Issue3421()
212+
{
213+
await Run();
214+
}
215+
210216
[Test]
211217
public async Task Issue2260SwitchString()
212218
{

ICSharpCode.Decompiler.Tests/Output/CSharpAmbienceTests.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,17 @@ public void AutomaticProperty(ConversionFlags flags, string expectedOutput)
283283
[TestCase(ILSpyMainTreeViewMemberFlags, "this[int] : int")]
284284
public void Indexer(ConversionFlags flags, string expectedOutput)
285285
{
286-
var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetProperties(p => p.IsIndexer).Single();
286+
var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetProperties(p => p.IsIndexer && !p.IsExplicitInterfaceImplementation).Single();
287+
ambience.ConversionFlags = flags;
288+
289+
Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput));
290+
}
291+
292+
[TestCase(StandardConversionFlags, "int Interface.this[int index] { get; }")]
293+
[TestCase(ILSpyMainTreeViewMemberFlags, "Interface.this[int] : int")]
294+
public void ExplicitIndexer(ConversionFlags flags, string expectedOutput)
295+
{
296+
var prop = compilation.FindType(typeof(CSharpAmbienceTests.Program)).GetProperties(p => p.IsIndexer && p.IsExplicitInterfaceImplementation).Single();
287297
ambience.ConversionFlags = flags;
288298

289299
Assert.That(ambience.ConvertSymbol(prop), Is.EqualTo(expectedOutput));
@@ -323,7 +333,12 @@ ref struct RefStruct { }
323333
readonly struct ReadonlyStruct { }
324334
readonly ref struct ReadonlyRefStruct { }
325335

326-
class Program
336+
interface Interface
337+
{
338+
int this[int x] { get; }
339+
}
340+
341+
class Program : Interface
327342
{
328343
int test;
329344
const int TEST2 = 2;
@@ -336,6 +351,12 @@ public int this[int index] {
336351
}
337352
}
338353

354+
int Interface.this[int index] {
355+
get {
356+
return index;
357+
}
358+
}
359+
339360
public event EventHandler ProgramChanged;
340361

341362
public event EventHandler SomeEvent {

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,21 @@ public async Task CustomShortCircuitOperators([ValueSource(nameof(defaultOptions
233233
[Test]
234234
public async Task ExceptionHandling([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
235235
{
236-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings {
237-
NullPropagation = false,
236+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
237+
settings.NullPropagation = false;
238238
// legacy csc generates a dead store in debug builds
239-
RemoveDeadStores = (cscOptions == CompilerOptions.None),
240-
FileScopedNamespaces = false,
239+
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
240+
settings.FileScopedNamespaces = false;
241241
});
242242
}
243243

244244
[Test]
245245
public async Task Switch([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
246246
{
247-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings {
247+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
248248
// legacy csc generates a dead store in debug builds
249-
RemoveDeadStores = (cscOptions == CompilerOptions.None),
250-
SwitchExpressions = false,
251-
FileScopedNamespaces = false,
249+
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
250+
settings.SwitchExpressions = false;
252251
});
253252
}
254253

@@ -267,7 +266,10 @@ public async Task ReduceNesting([ValueSource(nameof(defaultOptions))] CompilerOp
267266
[Test]
268267
public async Task DelegateConstruction([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions)
269268
{
270-
await RunForLibrary(cscOptions: cscOptions);
269+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
270+
settings.QueryExpressions = false;
271+
settings.NullableReferenceTypes = false;
272+
});
271273
}
272274

273275
[Test]
@@ -293,9 +295,9 @@ public async Task Using([ValueSource(nameof(defaultOptions))] CompilerOptions cs
293295
{
294296
await RunForLibrary(
295297
cscOptions: cscOptions,
296-
decompilerSettings: new DecompilerSettings {
297-
UseEnhancedUsing = false,
298-
FileScopedNamespaces = false,
298+
configureDecompiler: settings => {
299+
settings.UseEnhancedUsing = false;
300+
settings.FileScopedNamespaces = false;
299301
}
300302
);
301303
}
@@ -327,11 +329,11 @@ public async Task Generics([ValueSource(nameof(defaultOptions))] CompilerOptions
327329
[Test]
328330
public async Task Loops([ValueSource(nameof(defaultOptionsWithMcs))] CompilerOptions cscOptions)
329331
{
330-
DecompilerSettings settings = Tester.GetSettings(cscOptions);
331-
// legacy csc generates a dead store in debug builds
332-
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
333-
settings.UseExpressionBodyForCalculatedGetterOnlyProperties = false;
334-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: settings);
332+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => {
333+
// legacy csc generates a dead store in debug builds
334+
settings.RemoveDeadStores = (cscOptions == CompilerOptions.None);
335+
settings.UseExpressionBodyForCalculatedGetterOnlyProperties = false;
336+
});
335337
}
336338

337339
[Test]
@@ -440,9 +442,7 @@ public async Task VariableNaming([ValueSource(nameof(defaultOptions))] CompilerO
440442
[Test]
441443
public async Task VariableNamingWithoutSymbols([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
442444
{
443-
var settings = Tester.GetSettings(cscOptions);
444-
settings.UseDebugSymbols = false;
445-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: settings);
445+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.UseDebugSymbols = false);
446446
}
447447

448448
[Test]
@@ -474,7 +474,7 @@ public async Task AsyncUsing([ValueSource(nameof(roslyn3OrNewerOptions))] Compil
474474
{
475475
await RunForLibrary(
476476
cscOptions: cscOptions,
477-
decompilerSettings: new DecompilerSettings { UseEnhancedUsing = false, FileScopedNamespaces = false }
477+
configureDecompiler: settings => { settings.UseEnhancedUsing = false; }
478478
);
479479
}
480480

@@ -499,7 +499,7 @@ public async Task NativeInts([ValueSource(nameof(roslyn3OrNewerWithNet40Options)
499499
[Test]
500500
public async Task FileScopedNamespaces([ValueSource(nameof(roslyn4OrNewerOptions))] CompilerOptions cscOptions)
501501
{
502-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings());
502+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.FileScopedNamespaces = true);
503503
}
504504

505505
[Test]
@@ -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
{
@@ -595,7 +601,7 @@ public async Task ConstantsTests([ValueSource(nameof(defaultOptions))] CompilerO
595601
[Test]
596602
public async Task Issue1080([ValueSource(nameof(roslynOnlyOptions))] CompilerOptions cscOptions)
597603
{
598-
await RunForLibrary(cscOptions: cscOptions, decompilerSettings: new DecompilerSettings(CSharp.LanguageVersion.CSharp6));
604+
await RunForLibrary(cscOptions: cscOptions, configureDecompiler: settings => settings.SetLanguageVersion(CSharp.LanguageVersion.CSharp6));
599605
}
600606

601607
[Test]
@@ -706,12 +712,12 @@ public async Task MetadataAttributes([ValueSource(nameof(defaultOptions))] Compi
706712
await RunForLibrary(cscOptions: cscOptions);
707713
}
708714

709-
async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
715+
async Task RunForLibrary([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, Action<DecompilerSettings> configureDecompiler = null)
710716
{
711-
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, decompilerSettings);
717+
await Run(testName, asmOptions | AssemblerOptions.Library, cscOptions | CompilerOptions.Library, configureDecompiler);
712718
}
713719

714-
async Task Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, DecompilerSettings decompilerSettings = null)
720+
async Task Run([CallerMemberName] string testName = null, AssemblerOptions asmOptions = AssemblerOptions.None, CompilerOptions cscOptions = CompilerOptions.None, Action<DecompilerSettings> configureDecompiler = null)
715721
{
716722
var csFile = Path.Combine(TestCasePath, testName + ".cs");
717723
var exeFile = TestsAssemblyOutput.GetFilePath(TestCasePath, testName, Tester.GetSuffix(cscOptions) + ".exe");
@@ -733,7 +739,9 @@ async Task Run([CallerMemberName] string testName = null, AssemblerOptions asmOp
733739
}
734740

735741
// 2. Decompile
736-
var decompiled = await Tester.DecompileCSharp(exeFile, decompilerSettings ?? Tester.GetSettings(cscOptions)).ConfigureAwait(false);
742+
var settings = Tester.GetSettings(cscOptions);
743+
configureDecompiler?.Invoke(settings);
744+
var decompiled = await Tester.DecompileCSharp(exeFile, settings).ConfigureAwait(false);
737745

738746
// 3. Compile
739747
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).Append("EXPECTED_OUTPUT").ToArray());

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,6 @@ public static void CollectionInitializerInsideObjectInitializers()
318318
};
319319
}
320320

321-
public static void NotAStructInitializer_DefaultConstructor()
322-
{
323-
InitializerTests.StructData data = new InitializerTests.StructData();
324-
data.Field = 1;
325-
data.Property = 2;
326-
InitializerTests.X(InitializerTests.Y(), data);
327-
}
328-
329321
public static void StructInitializer_DefaultConstructor()
330322
{
331323
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData {
@@ -334,14 +326,6 @@ public static void StructInitializer_DefaultConstructor()
334326
});
335327
}
336328

337-
public static void NotAStructInitializer_ExplicitConstructor()
338-
{
339-
InitializerTests.StructData data = new InitializerTests.StructData(0);
340-
data.Field = 1;
341-
data.Property = 2;
342-
InitializerTests.X(InitializerTests.Y(), data);
343-
}
344-
345329
public static void StructInitializer_ExplicitConstructor()
346330
{
347331
InitializerTests.X(InitializerTests.Y(), new InitializerTests.StructData(0) {

0 commit comments

Comments
 (0)