Browse Source

Let ExtensionMethods, UseLambdaSyntax and UseEnhancedUsing raise the minimum version

These three settings were disabled by SetLanguageVersion for older
targets but, unlike every comparable syntax-preference setting, never
raised GetMinimumRequiredVersion while enabled - an omission that had
gone unnoticed in the handwritten version bookkeeping. Drop the
AffectsMinimumRequiredVersion escape hatch that reproduced it.

Assisted-by: Claude:claude-fable-5:Claude Code
pull/3970/head
Siegfried Pammer 1 month ago
parent
commit
401530b86d
  1. 17
      ICSharpCode.Decompiler.Generators/DecompilerSettingsGenerator.cs
  2. 6
      ICSharpCode.Decompiler/DecompilerSettings.cs

17
ICSharpCode.Decompiler.Generators/DecompilerSettingsGenerator.cs

@ -98,7 +98,7 @@ internal class DecompilerSettingsGenerator : IIncrementalGenerator @@ -98,7 +98,7 @@ internal class DecompilerSettingsGenerator : IIncrementalGenerator
readonly record struct SettingInfo(
string Namespace, string ClassName, string Accessibility, string PropertyName, string FieldName,
bool DefaultValue, int VersionValue, string? VersionName, string? Category, bool AffectsMinimumRequiredVersion,
bool DefaultValue, int VersionValue, string? VersionName, string? Category,
string FilePath, int SpanStart);
// A diagnostic captured during the transform; kept as plain values so the pipeline stays cacheable.
@ -122,12 +122,6 @@ namespace ICSharpCode.Decompiler @@ -122,12 +122,6 @@ namespace ICSharpCode.Decompiler
/// <summary>Initial value of the setting. Defaults to true.</summary>
public bool DefaultValue { get; set; } = true;
/// <summary>
/// Whether enabling the setting raises GetMinimumRequiredVersion() to the version the
/// setting was introduced in. Defaults to true; only meaningful on version-gated settings.
/// </summary>
public bool AffectsMinimumRequiredVersion { get; set; } = true;
}
}
@ -199,7 +193,6 @@ namespace ICSharpCode.Decompiler @@ -199,7 +193,6 @@ namespace ICSharpCode.Decompiler
}
bool defaultValue = true;
bool affectsMinimumRequiredVersion = true;
foreach (var named in attribute.NamedArguments)
{
// A named argument that failed to bind is already a compiler error; ignore it here.
@ -207,8 +200,6 @@ namespace ICSharpCode.Decompiler @@ -207,8 +200,6 @@ namespace ICSharpCode.Decompiler
continue;
if (named.Key == "DefaultValue")
defaultValue = namedValue;
else if (named.Key == "AffectsMinimumRequiredVersion")
affectsMinimumRequiredVersion = namedValue;
}
string fieldName = char.ToLowerInvariant(property.Name[0]) + property.Name.Substring(1);
@ -225,7 +216,6 @@ namespace ICSharpCode.Decompiler @@ -225,7 +216,6 @@ namespace ICSharpCode.Decompiler
versionValue,
versionName,
category,
affectsMinimumRequiredVersion,
node.SyntaxTree.FilePath,
node.SpanStart);
return new SettingResult(setting, diagnostics.Count == 0 ? null : diagnostics.ToEquatableArray());
@ -373,10 +363,7 @@ namespace ICSharpCode.Decompiler @@ -373,10 +363,7 @@ namespace ICSharpCode.Decompiler
builder.AppendLine("\t\t{");
foreach (var bucket in versionBuckets.Reverse())
{
var fields = bucket.Where(s => s.AffectsMinimumRequiredVersion).Select(s => s.FieldName).ToArray();
if (fields.Length == 0)
continue;
builder.AppendLine($"\t\t\tif ({string.Join(" || ", fields)})");
builder.AppendLine($"\t\t\tif ({string.Join(" || ", bucket.Select(s => s.FieldName))})");
builder.AppendLine($"\t\t\t\treturn global::ICSharpCode.Decompiler.CSharp.LanguageVersion.{bucket.First().VersionName};");
}
builder.AppendLine("\t\t\treturn global::ICSharpCode.Decompiler.CSharp.LanguageVersion.CSharp1;");

6
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -174,7 +174,7 @@ namespace ICSharpCode.Decompiler @@ -174,7 +174,7 @@ namespace ICSharpCode.Decompiler
/// Use C# 3 lambda syntax if possible.
/// </summary>
[Description("DecompilerSettings.UseLambdaSyntaxIfPossible")]
[DecompilerSetting(CSharp.LanguageVersion.CSharp3, AffectsMinimumRequiredVersion = false)]
[DecompilerSetting(CSharp.LanguageVersion.CSharp3)]
public partial bool UseLambdaSyntax { get; set; }
/// <summary>
@ -293,7 +293,7 @@ namespace ICSharpCode.Decompiler @@ -293,7 +293,7 @@ namespace ICSharpCode.Decompiler
/// Use enhanced using statements.
/// </summary>
[Description("DecompilerSettings.UseEnhancedUsing")]
[DecompilerSetting(CSharp.LanguageVersion.CSharp8_0, AffectsMinimumRequiredVersion = false)]
[DecompilerSetting(CSharp.LanguageVersion.CSharp8_0)]
public partial bool UseEnhancedUsing { get; set; }
/// <summary>
@ -350,7 +350,7 @@ namespace ICSharpCode.Decompiler @@ -350,7 +350,7 @@ namespace ICSharpCode.Decompiler
public partial bool UsingDeclarations { get; set; }
[Description("DecompilerSettings.UseExtensionMethodSyntax")]
[DecompilerSetting(CSharp.LanguageVersion.CSharp3, AffectsMinimumRequiredVersion = false)]
[DecompilerSetting(CSharp.LanguageVersion.CSharp3)]
public partial bool ExtensionMethods { get; set; }
[Description("DecompilerSettings.UseLINQExpressionSyntax")]

Loading…
Cancel
Save