Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.CodeAnalysis.LanguageService;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.CSharp.TypeStyle;
Expand Down Expand Up @@ -224,13 +225,14 @@ private static ExpressionSyntax GenerateTupleDeclaration(
.WithTrailingTrivia(parensDesignation.GetTrailingTrivia());
}

private static SyntaxNode GenerateTypeDeclaration(TypeSyntax typeSyntax, ITypeSymbol newTypeSymbol)
private static TypeSyntax GenerateTypeDeclaration(TypeSyntax typeSyntax, ITypeSymbol newTypeSymbol)
{
// We're going to be passed through the simplifier. Tell it to not just convert this back to var (as
// that would defeat the purpose of this refactoring entirely).
var newTypeSyntax = newTypeSymbol
.GenerateTypeSyntax(allowVar: false)
.WithTriviaFrom(typeSyntax);
.GenerateTypeSyntax(allowVar: false)
.WithAdditionalAnnotations(Simplifier.AddImportsAnnotation)
.WithTriviaFrom(typeSyntax);

return newTypeSyntax;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,9 @@ void M()
}
""", new TestParameters(options: ExplicitTypeEverywhere()));

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/23907")]
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/23907")]
[WorkItem("https://github.com/dotnet/roslyn/issues/24034")]
public async Task WithNormalFuncSynthesizedLambdaType()
{
var before = """
Expand All @@ -2670,11 +2672,13 @@ void Method()
}
""";
var after = """
using System;

class Program
{
void Method()
{
System.Func<int, string> x = (int i) => i.ToString();
Func<int, string> x = (int i) => i.ToString();
}
}
""";
Expand Down
Loading