Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't analyze local function bodies as though they are top level code #57623

Merged
merged 1 commit into from
Nov 12, 2021
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 @@ -7153,6 +7153,51 @@ static void Main(int X)
capabilities: EditAndContinueTestHelpers.Net6RuntimeCapabilities);
}

[Fact]
public void LocalFunctions_Update()
{
var src1 = @"
using System;

class C
{
void M()
{
N(3);

void N(int x)
{
if (x > 3)
{
x.ToString();
}
else
{
N(x - 1);
}
}
}
}";
var src2 = @"
using System;

class C
{
void M()
{
N(3);

void N(int x)
{
Console.WriteLine(""Hello"");
}
}
}";
var edits = GetTopEdits(src1, src2);

edits.VerifySemantics(SemanticEdit(SemanticEditKind.Update, c => c.GetMember("C.M"), preserveLocalVariables: true));
}

[Fact]
public void LocalFunction_In_Parameter_InsertWhole()
{
Expand Down Expand Up @@ -7727,7 +7772,6 @@ public void LocalFunctions_TypeParameter_Reorder()
"Reorder [B]@11 -> @9");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Move, "B", FeaturesResources.type_parameter),
Diagnostic(RudeEditKind.ChangingTypeParameters, "L", FeaturesResources.local_function));
}

Expand All @@ -7743,7 +7787,6 @@ public void LocalFunctions_TypeParameter_ReorderAndUpdate()
"Update [A]@9 -> [C]@11");

GetTopEdits(edits).VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.Move, "B", FeaturesResources.type_parameter),
Diagnostic(RudeEditKind.ChangingTypeParameters, "L", FeaturesResources.local_function));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,22 +728,6 @@ newNode is MethodDeclarationSyntax &&
}
}

protected override void ReportLocalFunctionsDeclarationRudeEdits(ArrayBuilder<RudeEditDiagnostic> diagnostics, Match<SyntaxNode> bodyMatch)
{
var bodyEditsForLambda = bodyMatch.GetTreeEdits();
var editMap = BuildEditMap(bodyEditsForLambda);
foreach (var edit in bodyEditsForLambda.Edits)
{
if (HasParentEdit(editMap, edit))
{
return;
}

var classifier = new EditClassifier(this, diagnostics, edit.OldNode, edit.NewNode, edit.Kind, bodyMatch);
classifier.ClassifyEdit();
}
}

protected override bool TryMatchActiveStatement(
SyntaxNode oldStatement,
int statementPart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ protected virtual string GetSuspensionPointDisplayName(SyntaxNode node, EditKind
protected abstract void GetStateMachineInfo(SyntaxNode body, out ImmutableArray<SyntaxNode> suspensionPoints, out StateMachineKinds kinds);
protected abstract TextSpan GetExceptionHandlingRegion(SyntaxNode node, out bool coversAllChildren);

protected abstract void ReportLocalFunctionsDeclarationRudeEdits(ArrayBuilder<RudeEditDiagnostic> diagnostics, Match<SyntaxNode> bodyMatch);

internal abstract void ReportTopLevelSyntacticRudeEdits(ArrayBuilder<RudeEditDiagnostic> diagnostics, Match<SyntaxNode> match, Edit<SyntaxNode> edit, Dictionary<SyntaxNode, EditKind> editMap);
internal abstract void ReportEnclosingExceptionHandlingRudeEdits(ArrayBuilder<RudeEditDiagnostic> diagnostics, IEnumerable<Edit<SyntaxNode>> exceptionHandlingEdits, SyntaxNode oldStatement, TextSpan newStatementSpan);
internal abstract void ReportOtherRudeEditsAroundActiveStatement(ArrayBuilder<RudeEditDiagnostic> diagnostics, Match<SyntaxNode> match, SyntaxNode oldStatement, SyntaxNode newStatement, bool isNonLeaf);
Expand Down Expand Up @@ -1430,7 +1428,7 @@ private Match<SyntaxNode> ComputeBodyMatch(

if (IsLocalFunction(match.OldRoot) && IsLocalFunction(match.NewRoot))
{
ReportLocalFunctionsDeclarationRudeEdits(diagnostics, match);
ReportMemberBodyUpdateRudeEdits(diagnostics, match.NewRoot, match.NewRoot.Span);
}

if (lazyRudeEdits != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,10 +1415,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue
Return True
End Select
End Function

Protected Overrides Sub ReportLocalFunctionsDeclarationRudeEdits(diagnostics As ArrayBuilder(Of RudeEditDiagnostic), bodyMatch As Match(Of SyntaxNode))
' VB has no local functions so we don't have anything to report
End Sub
#End Region

#Region "Diagnostic Info"
Expand Down