Skip to content

Commit 93a0900

Browse files
committed
Fix warnings
1 parent 074ffa9 commit 93a0900

File tree

7 files changed

+35
-37
lines changed

7 files changed

+35
-37
lines changed

BuildScripts/MakeInternal.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ForEach ($file in $inputFiles)
1313
{
1414
$content = Get-Content -path $file
1515
$content = $content -creplace "public(?=\s+(((abstract|sealed|static|record)\s+)?(partial\s+)?class|delegate|enum|interface|struct|record))", "internal"
16+
$content = ,"#pragma warning disable" + $content # $content is a list of lines, insert at the top
1617
$outputPath = Join-Path $outputFolder (Split-Path $file -Leaf)
1718
Out-File $outputPath UTF8 -InputObject $content
1819
}

src/FastExpressionCompiler.LightExpression/Expression.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ THE SOFTWARE.
2525

2626
// ReSharper disable CoVariantArrayConversion
2727
#nullable disable
28-
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
2928

3029
#define SUPPORTS_VISITOR
3130

src/FastExpressionCompiler.LightExpression/ExpressionVisitor.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ THE SOFTWARE.
3434
using FastExpressionCompiler.LightExpression.ImTools;
3535

3636
#nullable disable
37-
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
3837

3938
namespace FastExpressionCompiler.LightExpression;
4039

@@ -550,5 +549,3 @@ protected internal virtual Expression VisitRuntimeVariables(RuntimeVariablesExpr
550549

551550
protected internal virtual Expression VisitDebugInfo(DebugInfoExpression node) => node;
552551
}
553-
554-
#nullable restore

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,6 @@ public static void FreePooledParamTypes(Type[] paramTypes)
664664
Interlocked.Exchange(ref _paramTypesPoolWithElem0OfLength1[paramCount - 1], paramTypes);
665665
}
666666

667-
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
668-
669667
/// <summary>Collects the lambda info for the compilation</summary>
670668
public sealed class NestedLambdaInfo
671669
{
@@ -11436,4 +11434,3 @@ namespace System.Diagnostics.CodeAnalysis
1143611434
public sealed class UnscopedRefAttribute : Attribute { }
1143711435
}
1143811436
#endif
11439-
#nullable restore

src/FastExpressionCompiler/ILReader.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#nullable disable
2+
13
#if DEBUG
24
// #define DEBUG_INTERNALS
35
#endif
@@ -7,6 +9,7 @@
79
using System.Collections;
810
using System.Collections.Generic;
911
using System.Diagnostics;
12+
using System.Globalization;
1013
using System.Reflection;
1114
using System.Reflection.Emit;
1215
using System.Text;
@@ -22,8 +25,6 @@ namespace FastExpressionCompiler.LightExpression.ILDecoder;
2225
namespace FastExpressionCompiler.ILDecoder;
2326
#endif
2427

25-
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
26-
2728
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "Uses reflection on internal types and is not trim-compatible.")]
2829
public static class ILReaderFactory
2930
{
@@ -109,7 +110,11 @@ public static StringBuilder ToILString(this IEnumerable<ILInstruction> ilInstruc
109110
case OperandType.InlineMethod:
110111
var m = (InlineMethodInstruction)il;
111112
var sig = m.Method.ToString();
113+
#if NET
114+
var paramStart = sig.IndexOf('(', StringComparison.Ordinal);
115+
#else
112116
var paramStart = sig.IndexOf('(');
117+
#endif
113118
var paramList = paramStart == -1 ? "()" : sig.Substring(paramStart);
114119

115120
if (m.Method is MethodInfo met)
@@ -556,8 +561,12 @@ public class MethodBaseILProvider : IILProvider
556561

557562
public MethodBaseILProvider(MethodBase method)
558563
{
564+
#if NET
565+
ArgumentNullException.ThrowIfNull(method);
566+
#else
559567
if (method == null)
560568
throw new ArgumentNullException(nameof(method));
569+
#endif
561570

562571
var methodType = method.GetType();
563572
if (methodType != _runtimeMethodInfoType & methodType != _runtimeConstructorInfoType)
@@ -613,21 +622,21 @@ public DynamicMethodILProvider(DynamicMethod method)
613622

614623
public static class ILFormatter
615624
{
616-
public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8"));
617-
public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4"));
618-
public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2"));
619-
public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.Append($"V_{ordinal}");
620-
public static StringBuilder Label(StringBuilder sb, int offset) => sb.Append($"IL_{offset:D4}");
625+
public static StringBuilder Int32ToHex(StringBuilder sb, int int32) => sb.Append(int32.ToString("X8", CultureInfo.InvariantCulture));
626+
public static StringBuilder Int16ToHex(StringBuilder sb, int int16) => sb.Append(int16.ToString("X4", CultureInfo.InvariantCulture));
627+
public static StringBuilder Int8ToHex(StringBuilder sb, int int8) => sb.Append(int8.ToString("X2", CultureInfo.InvariantCulture));
628+
public static StringBuilder Argument(StringBuilder sb, int ordinal) => sb.AppendFormat(CultureInfo.InvariantCulture, "V_{0}", ordinal);
629+
public static StringBuilder Label(StringBuilder sb, int offset) => sb.AppendFormat(CultureInfo.InvariantCulture, "IL_{0:D4}", offset);
621630

622631
public static StringBuilder MultipleLabels(StringBuilder sb, int[] offsets)
623632
{
624633
var length = offsets.Length;
625634
for (var i = 0; i < length; i++)
626635
{
627-
sb.AppendFormat(i == 0 ? "(" : ", ");
636+
sb.Append(i == 0 ? "(" : ", ");
628637
sb.Append(Label(sb, offsets[i]));
629638
}
630-
sb.AppendFormat(")");
639+
sb.Append(')');
631640
return sb;
632641
}
633642

@@ -648,9 +657,9 @@ public static StringBuilder EscapedString(StringBuilder sb, string str)
648657
else if (ch == '\"')
649658
sb.Append("\\\"");
650659
else if (ch == '\\')
651-
sb.Append("\\");
660+
sb.Append('\\');
652661
else if (ch < 0x20 || ch >= 0x7f)
653-
sb.AppendFormat("\\u{0:x4}", (int)ch);
662+
sb.AppendFormat(CultureInfo.InvariantCulture, "\\u{0:x4}", (int)ch);
654663
else
655664
sb.Append(ch);
656665
}
@@ -663,10 +672,10 @@ public static StringBuilder SigByteArrayToString(StringBuilder sb, byte[] sig)
663672
var length = sig.Length;
664673
for (var i = 0; i < length; i++)
665674
{
666-
sb.AppendFormat(i == 0 ? "SIG [" : " ");
675+
sb.Append(i == 0 ? "SIG [" : " ");
667676
sb.Append(Int8ToHex(sb, sig[i]));
668677
}
669-
sb.AppendFormat("]");
678+
sb.Append(']');
670679
return sb;
671680
}
672681
}
@@ -820,5 +829,3 @@ public MemberInfo AsMember(int token)
820829

821830
public byte[] AsSignature(int token) => this[token] as byte[];
822831
}
823-
824-
#pragma warning restore CS1591

src/FastExpressionCompiler/ImTools.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,5 +1583,3 @@ public struct SmallSet16<K, TEq>() where TEq : struct, IEq<K>
15831583
/// <summary>Set with 16 keys on stack and entries baked by the single array</summary>
15841584
public SmallMap<K, SmallMap.Entry<K>, TEq, Size16, Stack16<int>, Stack16<SmallMap.Entry<K>>, SmallMap.SingleArrayEntries<K, SmallMap.Entry<K>, TEq>> Set;
15851585
}
1586-
1587-
#nullable restore

src/FastExpressionCompiler/TestTools.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
#nullable disable
2+
3+
using System;
24
using System.Linq;
35
using System.Text;
46
using System.Reflection;
@@ -19,18 +21,17 @@ namespace FastExpressionCompiler;
1921

2022
using FastExpressionCompiler.ILDecoder;
2123
using FastExpressionCompiler.ImTools;
24+
using System.Globalization;
2225
using System.Linq.Expressions;
2326
#endif
2427

25-
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
26-
2728
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "This is used for the testing purposes only.")]
2829
public static class TestTools
2930
{
30-
public static bool AllowPrintIL = false;
31-
public static bool AllowPrintCS = false;
32-
public static bool AllowPrintExpression = false;
33-
public static bool DisableAssertOpCodes = false;
31+
public static bool AllowPrintIL;
32+
public static bool AllowPrintCS;
33+
public static bool AllowPrintExpression;
34+
public static bool DisableAssertOpCodes;
3435

3536
static TestTools()
3637
{
@@ -567,7 +568,7 @@ public static bool StartsWith(string expected, string actual,
567568
string expectedName = "expected",
568569
[CallerArgumentExpression(nameof(actual))]
569570
string actualName = "actual") =>
570-
actual.StartsWith(expected) ? true : throw new AssertionException(
571+
actual.StartsWith(expected, StringComparison.Ordinal) ? true : throw new AssertionException(
571572
$"Expected string `StartsWith({expectedName}, {actualName})`, but found expected `{expected.ToCode()}` is not at start of `{actual.ToCode()}`");
572573
}
573574

@@ -628,9 +629,9 @@ class CallerMemberNameAttribute : Attribute { }
628629
class CallerLineNumberAttribute : Attribute { }
629630

630631
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
631-
class CallerArgumentExpression : Attribute
632+
class CallerArgumentExpressionAttribute : Attribute
632633
{
633-
public CallerArgumentExpression(string parameterName) { }
634+
public CallerArgumentExpressionAttribute(string parameterName) { }
634635
}
635636
#endif
636637

@@ -993,7 +994,7 @@ public bool StartsWith(string expected, string actual,
993994
string expectedName = "<expected>",
994995
[CallerArgumentExpression(nameof(actual))]
995996
string actualName = "<actual>") =>
996-
actual.StartsWith(expected) ? true : throw new AssertionException(
997+
actual.StartsWith(expected, StringComparison.Ordinal) ? true : throw new AssertionException(
997998
$"Expected string `StartsWith({expectedName}, {actualName})`, but found expected `{expected.ToCode()}` is not at start of `{actual.ToCode()}`");
998999
}
9991000

@@ -1060,5 +1061,3 @@ public void Run<T>(T test, TestFlags flags = TestFlags.Default) where T : ITestX
10601061
}
10611062
}
10621063
}
1063-
1064-
#pragma warning restore CS1591

0 commit comments

Comments
 (0)