|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Collections.Immutable; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Linq.Expressions; |
5 | 6 | using System.Threading.Tasks; |
@@ -975,14 +976,27 @@ public override async Task<CSharpSyntaxNode> VisitGenericName(VBasic.Syntax.Gene |
975 | 976 | private async Task<SimpleNameSyntax> GenericNameAccountingForReducedParameters(VBSyntax.GenericNameSyntax node, ISymbol symbol) |
976 | 977 | { |
977 | 978 | SyntaxToken convertedIdentifier = ConvertIdentifier(node.Identifier); |
978 | | - var typeArgumentListSyntax = (TypeArgumentListSyntax)await node.TypeArgumentList.AcceptAsync(TriviaConvertingVisitor); |
979 | 979 | if (symbol.IsReducedTypeParameterMethod()) { |
980 | | - var commentedText = "/* " + typeArgumentListSyntax.ToFullString() + " */"; |
981 | | - var trailingTrivia = SyntaxFactory.Comment(commentedText); |
982 | | - return SyntaxFactory.IdentifierName(convertedIdentifier).WithTrailingTrivia(trailingTrivia); |
| 980 | + if (symbol is IMethodSymbol vbMethod && CommonConversions.GetCsOriginalSymbolOrNull(symbol) is IMethodSymbol csSymbolWithInferredTypeParametersSet) { |
| 981 | + var argSubstitutions = vbMethod.TypeParameters |
| 982 | + .Zip(vbMethod.TypeArguments, (parameter, arg) => (parameter, arg)) |
| 983 | + .ToDictionary(x => x.parameter.Name, x => x.arg); |
| 984 | + var allTypeArgs = csSymbolWithInferredTypeParametersSet.GetTypeArguments() |
| 985 | + .Select(a => a.Kind == SymbolKind.TypeParameter && argSubstitutions.TryGetValue(a.Name, out var t) ? t : a).ToArray(); |
| 986 | + return (SimpleNameSyntax)CommonConversions.CsSyntaxGenerator.GenericName(convertedIdentifier.Text, allTypeArgs); |
| 987 | + } |
| 988 | + var commentedText = "/* " + (await ConvertTypeArgumentList(node)).ToFullString() + " */"; |
| 989 | + var error = SyntaxFactory.ParseLeadingTrivia($"#error Conversion error: Could not convert all type parameters, so they've been commented out. Inferred type may be different{Environment.NewLine}"); |
| 990 | + var partialConversion = SyntaxFactory.Comment(commentedText); |
| 991 | + return SyntaxFactory.IdentifierName(convertedIdentifier).WithPrependedLeadingTrivia(error).WithTrailingTrivia(partialConversion); |
983 | 992 | } |
984 | 993 |
|
985 | | - return SyntaxFactory.GenericName(convertedIdentifier, typeArgumentListSyntax); |
| 994 | + return SyntaxFactory.GenericName(convertedIdentifier, await ConvertTypeArgumentList(node)); |
| 995 | + } |
| 996 | + |
| 997 | + private async Task<TypeArgumentListSyntax> ConvertTypeArgumentList(VBSyntax.GenericNameSyntax node) |
| 998 | + { |
| 999 | + return (TypeArgumentListSyntax)await node.TypeArgumentList.AcceptAsync(TriviaConvertingVisitor); |
986 | 1000 | } |
987 | 1001 |
|
988 | 1002 | public override async Task<CSharpSyntaxNode> VisitTypeArgumentList(VBasic.Syntax.TypeArgumentListSyntax node) |
|
0 commit comments