Skip to content

Commit

Permalink
Support for partial type EnC and moving declarations across files (#5…
Browse files Browse the repository at this point in the history
…1187)

* Partial types
Call AnalyzeChangedMemberBody from semantic analysis
  • Loading branch information
tmat authored Feb 23, 2021
1 parent dbe9d2f commit fc7b737
Show file tree
Hide file tree
Showing 83 changed files with 9,045 additions and 3,584 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,16 @@ internal VariableSlotAllocator TryCreateVariableSlotAllocator(EmitBaseline basel
symbolMap = MapToMetadataSymbolMatcher;
}

var previousMethod = mappedMethod.PreviousMethod;
if (previousMethod is null)
{
previousMethod = (IMethodSymbolInternal)symbolMap.MapDefinitionOrNamespace(topLevelMethod);
}

return new EncVariableSlotAllocator(
symbolMap,
mappedMethod.SyntaxMap,
mappedMethod.PreviousMethod,
previousMethod,
methodId,
previousLocals,
lambdaMap,
Expand Down
4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/Emit/SemanticEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public struct SemanticEdit : IEquatable<SemanticEdit>
/// </summary>
/// <param name="kind">The type of edit.</param>
/// <param name="oldSymbol">
/// The symbol from the earlier compilation, or null if the edit represents an addition.
/// The symbol from the earlier compilation, or null if the edit represents an addition or an update of the symbol from the previous compilation that exactly matches <paramref name="newSymbol"/>.
/// </param>
/// <param name="newSymbol">
/// The symbol from the later compilation, or null if the edit represents a deletion.
Expand All @@ -74,7 +74,7 @@ public struct SemanticEdit : IEquatable<SemanticEdit>
/// </exception>
public SemanticEdit(SemanticEditKind kind, ISymbol? oldSymbol, ISymbol? newSymbol, Func<SyntaxNode, SyntaxNode?>? syntaxMap = null, bool preserveLocalVariables = false)
{
if (oldSymbol == null && kind != SemanticEditKind.Insert)
if (oldSymbol == null && kind is not (SemanticEditKind.Insert or SemanticEditKind.Update))
{
throw new ArgumentNullException(nameof(oldSymbol));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
using Microsoft.CodeAnalysis.CSharp.UnitTests;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.EditAndContinue.UnitTests
{
[UseExportProvider]
public class ActiveStatementTests_Methods : EditingTestBase
{
#region Methods
Expand Down Expand Up @@ -43,12 +45,17 @@ static void Main(string[] args)
}
";

// TODO (bug 755959): better deleted active statement span
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "class C", FeaturesResources.method));
EditAndContinueValidation.VerifySemantics(
new[] { edits },
new[]
{
DocumentResults(
active,
diagnostics: new[] { Diagnostic(RudeEditKind.Delete, "class C", DeletedSymbolDisplay(FeaturesResources.method, "Goo(int)")) })
});
}

[Fact]
Expand Down Expand Up @@ -550,7 +557,7 @@ class C
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "get"));
Diagnostic(RudeEditKind.DeleteActiveStatement, "get", FeaturesResources.code));
}

[Fact]
Expand All @@ -575,7 +582,7 @@ public void Property_BlockBodyToExpressionBody2()
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "int P", CSharpFeaturesResources.property_setter));
Diagnostic(RudeEditKind.Delete, "int P", DeletedSymbolDisplay(CSharpFeaturesResources.property_setter, "P.set")));
}

[Fact]
Expand All @@ -601,7 +608,7 @@ class C

// Can be improved with https://github.com/dotnet/roslyn/issues/22696
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "int P"));
Diagnostic(RudeEditKind.DeleteActiveStatement, "int P", FeaturesResources.code));
}

#endregion
Expand Down Expand Up @@ -654,7 +661,7 @@ public void Indexer_BlockBodyToExpressionBody2()
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.Delete, "int this[int a]", CSharpFeaturesResources.indexer_setter));
Diagnostic(RudeEditKind.Delete, "int this[int a]", DeletedSymbolDisplay(CSharpFeaturesResources.indexer_setter, "this[int].set")));
}

[Fact]
Expand Down Expand Up @@ -756,9 +763,10 @@ public T this[int i]
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

// Rude edits of active statements (AS:1) are not reported if the top-level edits are rude.
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, @"stringCollection[1] = ""hello"";"),
Diagnostic(RudeEditKind.GenericTypeUpdate, "set", CSharpFeaturesResources.indexer_setter));
Diagnostic(RudeEditKind.GenericTypeUpdate, "set", CSharpFeaturesResources.indexer_setter),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "stringCollection[1] = \"hello\";"));
}

[Fact]
Expand Down Expand Up @@ -858,9 +866,10 @@ public T this[int i]
var edits = GetTopEdits(src1, src2);
var active = GetActiveStatements(src1, src2);

// Rude edits of active statements (AS:1) are not reported if the top-level edits are rude.
edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Console.WriteLine(stringCollection[1]);"),
Diagnostic(RudeEditKind.GenericTypeUpdate, "get", CSharpFeaturesResources.indexer_getter));
Diagnostic(RudeEditKind.GenericTypeUpdate, "get", CSharpFeaturesResources.indexer_getter),
Diagnostic(RudeEditKind.ActiveStatementUpdate, "Console.WriteLine(stringCollection[1]);"));
}

[Fact]
Expand Down Expand Up @@ -959,7 +968,7 @@ public T this[int i]
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"));
Diagnostic(RudeEditKind.DeleteActiveStatement, "{", FeaturesResources.code));
}

[Fact]
Expand Down Expand Up @@ -1058,7 +1067,7 @@ public T this[int i]
var active = GetActiveStatements(src1, src2);

edits.VerifyRudeDiagnostics(active,
Diagnostic(RudeEditKind.DeleteActiveStatement, "{"));
Diagnostic(RudeEditKind.DeleteActiveStatement, "{", FeaturesResources.code));
}

#endregion
Expand Down
Loading

0 comments on commit fc7b737

Please sign in to comment.