diff --git a/ExternalProjects/BizHawk.Analyzer/AmbiguousMoneyToFloatConversionAnalyzer.cs b/ExternalProjects/BizHawk.Analyzer/AmbiguousMoneyToFloatConversionAnalyzer.cs index 085e740570..1418e9cb8c 100644 --- a/ExternalProjects/BizHawk.Analyzer/AmbiguousMoneyToFloatConversionAnalyzer.cs +++ b/ExternalProjects/BizHawk.Analyzer/AmbiguousMoneyToFloatConversionAnalyzer.cs @@ -26,27 +26,24 @@ public sealed class AmbiguousMoneyToFloatConversionAnalyzer : DiagnosticAnalyzer context.EnableConcurrentExecution(); context.RegisterCompilationStartAction(initContext => { - var decimalSym = initContext.Compilation.GetTypeByMetadataName("System.Decimal")!; - var doubleSym = initContext.Compilation.GetTypeByMetadataName("System.Double")!; - var floatSym = initContext.Compilation.GetTypeByMetadataName("System.Single")!; initContext.RegisterOperationAction(oac => { var conversionOp = (IConversionOperation) oac.Operation; - var typeOutput = conversionOp.Type; - var typeInput = conversionOp.Operand.Type; + var typeOutput = conversionOp.Type?.SpecialType ?? SpecialType.None; + var typeInput = conversionOp.Operand.Type?.SpecialType ?? SpecialType.None; bool isToDecimal; bool isDoublePrecision; - if (decimalSym.Matches(typeOutput)) + if (typeOutput is SpecialType.System_Decimal) { - if (doubleSym.Matches(typeInput)) isDoublePrecision = true; - else if (floatSym.Matches(typeInput)) isDoublePrecision = false; + if (typeInput is SpecialType.System_Double) isDoublePrecision = true; + else if (typeInput is SpecialType.System_Single) isDoublePrecision = false; else return; isToDecimal = true; } - else if (decimalSym.Matches(typeInput)) + else if (typeInput is SpecialType.System_Decimal) { - if (doubleSym.Matches(typeOutput)) isDoublePrecision = true; - else if (floatSym.Matches(typeOutput)) isDoublePrecision = false; + if (typeOutput is SpecialType.System_Double) isDoublePrecision = true; + else if (typeOutput is SpecialType.System_Single) isDoublePrecision = false; else return; isToDecimal = false; } diff --git a/ExternalProjects/BizHawk.Analyzer/TernaryInferredTypeMismatchAnalyzer.cs b/ExternalProjects/BizHawk.Analyzer/TernaryInferredTypeMismatchAnalyzer.cs index 7aa8011d34..519fe0b23d 100644 --- a/ExternalProjects/BizHawk.Analyzer/TernaryInferredTypeMismatchAnalyzer.cs +++ b/ExternalProjects/BizHawk.Analyzer/TernaryInferredTypeMismatchAnalyzer.cs @@ -25,8 +25,6 @@ public sealed class TernaryInferredTypeMismatchAnalyzer : DiagnosticAnalyzer context.EnableConcurrentExecution(); context.RegisterCompilationStartAction(initContext => { - var objectSym = initContext.Compilation.GetTypeByMetadataName("System.Object")!; - var stringSym = initContext.Compilation.GetTypeByMetadataName("System.String")!; initContext.RegisterOperationAction(oac => { var ifelseOrTernaryOp = (IConditionalOperation) oac.Operation; @@ -37,7 +35,7 @@ public sealed class TernaryInferredTypeMismatchAnalyzer : DiagnosticAnalyzer var ternaryOp = ifelseOrTernaryOp; var typeTernary = ternaryOp.Type!; #if false // never hit; either both branches are string and there are no conversions, or conversions are necessary - if (stringSym.Matches(typeTernary)) return; + if (typeTernary.SpecialType is SpecialType.System_String) return; #endif var lhs = ternaryOp.WhenTrue; var rhs = ternaryOp.WhenFalse; @@ -52,17 +50,17 @@ public sealed class TernaryInferredTypeMismatchAnalyzer : DiagnosticAnalyzer var fatal = false; IOperation flaggedOp = ternaryOp; string message; - if (stringSym.Matches(typeLHS)) + if (typeLHS.SpecialType is SpecialType.System_String) { flaggedOp = rhs; message = ERR_MSG_OBJECT; } - else if (stringSym.Matches(typeRHS)) + else if (typeRHS.SpecialType is SpecialType.System_String) { flaggedOp = lhs; message = ERR_MSG_OBJECT; } - else if (objectSym.Matches(typeTernary)) + else if (typeTernary.SpecialType is SpecialType.System_Object) { fatal = true; message = "ternary branches are upcast to object! add ToString calls, or convert one to the other's type"; diff --git a/ExternalProjects/BizHawk.Analyzer/UseSimplerBoolFlipAnalyzer.cs b/ExternalProjects/BizHawk.Analyzer/UseSimplerBoolFlipAnalyzer.cs index 32b83543eb..45dfe246b0 100644 --- a/ExternalProjects/BizHawk.Analyzer/UseSimplerBoolFlipAnalyzer.cs +++ b/ExternalProjects/BizHawk.Analyzer/UseSimplerBoolFlipAnalyzer.cs @@ -28,7 +28,6 @@ public sealed class UseSimplerBoolFlipAnalyzer : DiagnosticAnalyzer { context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); context.EnableConcurrentExecution(); - ISymbol? boolSym = null; context.RegisterOperationAction( oac => { @@ -43,8 +42,7 @@ public sealed class UseSimplerBoolFlipAnalyzer : DiagnosticAnalyzer } var operation = (ICompoundAssignmentOperation) oac.Operation; if (operation.OperatorKind is not BinaryOperatorKind.ExclusiveOr) return; - boolSym ??= oac.Compilation.GetTypeByMetadataName("System.Boolean")!; - if (!boolSym.Matches(operation.Type)) return; + if (operation.Type?.SpecialType is not SpecialType.System_Boolean) return; if (operation.Value.Kind is not OperationKind.Literal) return; var lhsOp = operation.Target; bool lhsIsSimpleExpr; diff --git a/ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs b/ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs index db59f3bc2f..6212856ec2 100644 --- a/ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs +++ b/ExternalProjects/BizHawk.Analyzer/UseTypeofOperatorAnalyzer.cs @@ -39,7 +39,7 @@ public sealed class UseTypeofOperatorAnalyzer : DiagnosticAnalyzer { var operation = (IInvocationOperation) oac.Operation; if (operation.IsImplicit || operation.Instance is null) return; - objectDotGetTypeSym ??= oac.Compilation.GetTypeByMetadataName("System.Object")!.GetMembers("GetType")[0]; + objectDotGetTypeSym ??= oac.Compilation.GetSpecialType(SpecialType.System_Object).GetMembers("GetType")[0]; if (!objectDotGetTypeSym.Matches(operation.TargetMethod)) return; if (operation.Instance.Syntax is not ThisExpressionSyntax and not IdentifierNameSyntax { Identifier.Text: "GetType" }) return; // called on something that isn't `this` var enclosingType = operation.SemanticModel!.GetDeclaredSymbol( diff --git a/References/BizHawk.Analyzer.dll b/References/BizHawk.Analyzer.dll index 2b383fabf2..b18ae032f2 100644 Binary files a/References/BizHawk.Analyzer.dll and b/References/BizHawk.Analyzer.dll differ