|
1 | 1 | using System.Collections.Immutable; |
2 | 2 | using System.Data; |
3 | 3 | using System.Globalization; |
| 4 | +using System.Linq; |
4 | 5 | using ICSharpCode.CodeConverter.CSharp.Replacements; |
5 | 6 | using ICSharpCode.CodeConverter.Util.FromRoslyn; |
6 | 7 | using Microsoft.CodeAnalysis.CSharp; |
@@ -70,9 +71,13 @@ private static Dictionary<ITypeSymbol, string> CreateConvertMethodsLookupByRetur |
70 | 71 |
|
71 | 72 | var convertMethods = convertType.GetMembers().Where(m => |
72 | 73 | m.Name.StartsWith("To", StringComparison.Ordinal) && m.GetParameters().Length == 1); |
| 74 | + |
| 75 | +#pragma warning disable RS1024 // Compare symbols correctly - GroupBy and ToDictionary use the same logic to dedupe as to lookup, so it doesn't matter which equality is used |
73 | 76 | var methodsByType = convertMethods |
74 | 77 | .GroupBy(m => new { ReturnType = m.GetReturnType(), Name = $"{ConvertType.FullName}.{m.Name}" }) |
75 | 78 | .ToDictionary(m => m.Key.ReturnType, m => m.Key.Name); |
| 79 | +#pragma warning restore RS1024 // Compare symbols correctly |
| 80 | + |
76 | 81 | return methodsByType; |
77 | 82 | } |
78 | 83 |
|
@@ -519,7 +524,7 @@ private ExpressionSyntax HoistByRefDeclaration(VBSyntax.SimpleArgumentSyntax nod |
519 | 524 | { |
520 | 525 | string prefix = $"arg{argName}"; |
521 | 526 | var expressionTypeInfo = _semanticModel.GetTypeInfo(node.Expression); |
522 | | - bool useVar = expressionTypeInfo.Type?.Equals(expressionTypeInfo.ConvertedType) == true && !CommonConversions.ShouldPreferExplicitType(node.Expression, expressionTypeInfo.ConvertedType, out var _); |
| 527 | + bool useVar = expressionTypeInfo.Type?.Equals(expressionTypeInfo.ConvertedType, SymbolEqualityComparer.IncludeNullability) == true && !CommonConversions.ShouldPreferExplicitType(node.Expression, expressionTypeInfo.ConvertedType, out var _); |
523 | 528 | var typeSyntax = CommonConversions.GetTypeSyntax(expressionTypeInfo.ConvertedType, useVar); |
524 | 529 |
|
525 | 530 | if (refLValue is ElementAccessExpressionSyntax eae) { |
@@ -866,7 +871,7 @@ public override async Task<CSharpSyntaxNode> VisitBinaryExpression(VBasic.Syntax |
866 | 871 | } |
867 | 872 |
|
868 | 873 | omitConversion |= lhsTypeInfo.Type != null && rhsTypeInfo.Type != null && |
869 | | - lhsTypeInfo.Type.IsEnumType() && Equals(lhsTypeInfo.Type, rhsTypeInfo.Type) |
| 874 | + lhsTypeInfo.Type.IsEnumType() && SymbolEqualityComparer.IncludeNullability.Equals(lhsTypeInfo.Type, rhsTypeInfo.Type) |
870 | 875 | && !node.IsKind(VBasic.SyntaxKind.AddExpression, VBasic.SyntaxKind.SubtractExpression, VBasic.SyntaxKind.MultiplyExpression, VBasic.SyntaxKind.DivideExpression, VBasic.SyntaxKind.IntegerDivideExpression, VBasic.SyntaxKind.ModuloExpression) |
871 | 876 | && forceLhsTargetType == null && forceRhsTargetType == null; |
872 | 877 | lhs = omitConversion ? lhs : CommonConversions.TypeConversionAnalyzer.AddExplicitConversion(node.Left, lhs, forceTargetType: forceLhsTargetType); |
@@ -1032,7 +1037,7 @@ private static bool IsElementAtOrDefaultInvocation(ISymbol invocationSymbol, ISy |
1032 | 1037 | { |
1033 | 1038 | return (expressionSymbol != null |
1034 | 1039 | && (invocationSymbol?.Name == nameof(Enumerable.ElementAtOrDefault) |
1035 | | - && !expressionSymbol.Equals(invocationSymbol))); |
| 1040 | + && !expressionSymbol.Equals(invocationSymbol, SymbolEqualityComparer.IncludeNullability))); |
1036 | 1041 | } |
1037 | 1042 |
|
1038 | 1043 | private ExpressionSyntax GetElementAtOrDefaultExpression(ISymbol expressionType, |
@@ -1671,7 +1676,7 @@ RefConversion GetRefConversion(VBSyntax.ExpressionSyntax expression) |
1671 | 1676 | IsRefArrayAcces(expression)) { |
1672 | 1677 |
|
1673 | 1678 | var typeInfo = _semanticModel.GetTypeInfo(expression); |
1674 | | - bool isTypeMismatch = typeInfo.Type == null || !typeInfo.Type.Equals(typeInfo.ConvertedType); |
| 1679 | + bool isTypeMismatch = typeInfo.Type == null || !typeInfo.Type.Equals(typeInfo.ConvertedType, SymbolEqualityComparer.IncludeNullability); |
1675 | 1680 |
|
1676 | 1681 | if (isTypeMismatch) { |
1677 | 1682 | return RefConversion.PreAndPostAssignment; |
|
0 commit comments