From eddbc4f4899c1ef0d53a33220778e45fc88f7b9b Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 24 Oct 2025 17:26:49 -0700 Subject: [PATCH] Fix warnings --- BuildScripts/MakeInternal.ps1 | 2 ++ .../ExpressionVisitor.cs | 2 -- .../FastExpressionCompiler.cs | 1 - src/FastExpressionCompiler/ILReader.cs | 27 ++++++++++--------- src/FastExpressionCompiler/ImTools.cs | 2 -- src/FastExpressionCompiler/TestTools.cs | 19 ++++++------- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/BuildScripts/MakeInternal.ps1 b/BuildScripts/MakeInternal.ps1 index 0be3d1c7..10dbf547 100644 --- a/BuildScripts/MakeInternal.ps1 +++ b/BuildScripts/MakeInternal.ps1 @@ -13,6 +13,8 @@ ForEach ($file in $inputFiles) { $content = Get-Content -path $file $content = $content -creplace "public(?=\s+(((abstract|sealed|static|record)\s+)?(partial\s+)?class|delegate|enum|interface|struct|record))", "internal" + $content = $content -replace "^\s*#pragma warning.*$", "" # remove any #pragma directive that could be reactivating our global disable + $content = ,"#pragma warning disable" + $content # $content is a list of lines, insert at the top $outputPath = Join-Path $outputFolder (Split-Path $file -Leaf) Out-File $outputPath UTF8 -InputObject $content } diff --git a/src/FastExpressionCompiler.LightExpression/ExpressionVisitor.cs b/src/FastExpressionCompiler.LightExpression/ExpressionVisitor.cs index 62923417..efe2c172 100644 --- a/src/FastExpressionCompiler.LightExpression/ExpressionVisitor.cs +++ b/src/FastExpressionCompiler.LightExpression/ExpressionVisitor.cs @@ -550,5 +550,3 @@ protected internal virtual Expression VisitRuntimeVariables(RuntimeVariablesExpr protected internal virtual Expression VisitDebugInfo(DebugInfoExpression node) => node; } - -#nullable restore \ No newline at end of file diff --git a/src/FastExpressionCompiler/FastExpressionCompiler.cs b/src/FastExpressionCompiler/FastExpressionCompiler.cs index a3d6b321..2ee422ec 100644 --- a/src/FastExpressionCompiler/FastExpressionCompiler.cs +++ b/src/FastExpressionCompiler/FastExpressionCompiler.cs @@ -11436,4 +11436,3 @@ namespace System.Diagnostics.CodeAnalysis public sealed class UnscopedRefAttribute : Attribute { } } #endif -#nullable restore diff --git a/src/FastExpressionCompiler/ILReader.cs b/src/FastExpressionCompiler/ILReader.cs index d51690ea..bfd450cd 100644 --- a/src/FastExpressionCompiler/ILReader.cs +++ b/src/FastExpressionCompiler/ILReader.cs @@ -1,3 +1,5 @@ +#nullable disable + #if DEBUG // #define DEBUG_INTERNALS #endif @@ -7,6 +9,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.Reflection; using System.Reflection.Emit; using System.Text; @@ -613,21 +616,21 @@ public DynamicMethodILProvider(DynamicMethod method) public static class ILFormatter { - public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8")); - public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4")); - public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2")); - public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.Append($"V_{ordinal}"); - public static StringBuilder Label(StringBuilder sb, int offset) => sb.Append($"IL_{offset:D4}"); + public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8", CultureInfo.InvariantCulture)); + public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4", CultureInfo.InvariantCulture)); + public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2", CultureInfo.InvariantCulture)); + public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.AppendFormat(CultureInfo.InvariantCulture, "V_{0}", ordinal); + public static StringBuilder Label(StringBuilder sb, int offset) => sb.AppendFormat(CultureInfo.InvariantCulture, "IL_{0:D4}", offset); public static StringBuilder MultipleLabels(StringBuilder sb, int[] offsets) { var length = offsets.Length; for (var i = 0; i < length; i++) { - sb.AppendFormat(i == 0 ? "(" : ", "); + sb.Append(i == 0 ? "(" : ", "); sb.Append(Label(sb, offsets[i])); } - sb.AppendFormat(")"); + sb.Append(')'); return sb; } @@ -648,9 +651,9 @@ public static StringBuilder EscapedString(StringBuilder sb, string str) else if (ch == '\"') sb.Append("\\\""); else if (ch == '\\') - sb.Append("\\"); + sb.Append('\\'); else if (ch < 0x20 || ch >= 0x7f) - sb.AppendFormat("\\u{0:x4}", (int)ch); + sb.AppendFormat(CultureInfo.InvariantCulture, "\\u{0:x4}", (int)ch); else sb.Append(ch); } @@ -663,10 +666,10 @@ public static StringBuilder SigByteArrayToString(StringBuilder sb, byte[] sig) var length = sig.Length; for (var i = 0; i < length; i++) { - sb.AppendFormat(i == 0 ? "SIG [" : " "); + sb.Append(i == 0 ? "SIG [" : " "); sb.Append(Int8ToHex(sb, sig[i])); } - sb.AppendFormat("]"); + sb.Append(']'); return sb; } } @@ -820,5 +823,3 @@ public MemberInfo AsMember(int token) public byte[] AsSignature(int token) => this[token] as byte[]; } - -#pragma warning restore CS1591 \ No newline at end of file diff --git a/src/FastExpressionCompiler/ImTools.cs b/src/FastExpressionCompiler/ImTools.cs index baee00e1..32014119 100644 --- a/src/FastExpressionCompiler/ImTools.cs +++ b/src/FastExpressionCompiler/ImTools.cs @@ -1583,5 +1583,3 @@ public struct SmallSet16() where TEq : struct, IEq /// Set with 16 keys on stack and entries baked by the single array public SmallMap, TEq, Size16, Stack16, Stack16>, SmallMap.SingleArrayEntries, TEq>> Set; } - -#nullable restore \ No newline at end of file diff --git a/src/FastExpressionCompiler/TestTools.cs b/src/FastExpressionCompiler/TestTools.cs index e10fe70b..11750a76 100644 --- a/src/FastExpressionCompiler/TestTools.cs +++ b/src/FastExpressionCompiler/TestTools.cs @@ -1,4 +1,6 @@ -using System; +#nullable disable + +using System; using System.Linq; using System.Text; using System.Reflection; @@ -19,6 +21,7 @@ namespace FastExpressionCompiler; using FastExpressionCompiler.ILDecoder; using FastExpressionCompiler.ImTools; +using System.Globalization; using System.Linq.Expressions; #endif @@ -27,10 +30,10 @@ namespace FastExpressionCompiler; [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is used for the testing purposes only.")] public static class TestTools { - public static bool AllowPrintIL = false; - public static bool AllowPrintCS = false; - public static bool AllowPrintExpression = false; - public static bool DisableAssertOpCodes = false; + public static bool AllowPrintIL; + public static bool AllowPrintCS; + public static bool AllowPrintExpression; + public static bool DisableAssertOpCodes; static TestTools() { @@ -628,9 +631,9 @@ class CallerMemberNameAttribute : Attribute { } class CallerLineNumberAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] -class CallerArgumentExpression : Attribute +class CallerArgumentExpressionAttribute : Attribute { - public CallerArgumentExpression(string parameterName) { } + public CallerArgumentExpressionAttribute(string parameterName) { } } #endif @@ -1060,5 +1063,3 @@ public void Run(T test, TestFlags flags = TestFlags.Default) where T : ITestX } } } - -#pragma warning restore CS1591 \ No newline at end of file