FastScriptReload icon indicating copy to clipboard operation
FastScriptReload copied to clipboard

The BuilderPatternFunctionsRewriter class has some incorrect handling methods.

Open Shiling1234 opened this issue 1 year ago • 1 comments

orgin code is: ` private static ClassA staicField;

    public static ClassA GetStaicField()
    {
        return staicField;
    }`

will be written to ` private static ClassA staicField;

    public static ClassA_Patched_0 GetStaicField()
    {
        return staicField;
    }`

The above code may lead to type mismatch errors.

Only "return this" needs to be rewrite. Perhaps it is necessary to add a check for whether there is a "return this".

static bool ReturnsThis(MethodDeclarationSyntax method)  
    {  
        var returnStatements = method.DescendantNodes().OfType<ReturnStatementSyntax>();  
        
       return returnStatements.All(r => r.Expression is ThisExpressionSyntax);
    }

Shiling1234 avatar Nov 10 '24 09:11 Shiling1234

Thanks - I'll try to have a look, btw if you already have a fix ready it'd be great to have that as PR.

I think rewritter you want is here FastScriptReload.Editor.Compilation.CodeRewriting.BuilderPatternFunctionsRewriter.BuilderPatternFunctionsRewriter

handzlikchris avatar Nov 11 '24 08:11 handzlikchris