Skip to content

Commit

Permalink
Disable EnC for more Primary Constructors scenarios (#67026)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyTs authored Feb 28, 2023
1 parent cfe9f31 commit 461c28c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18814,6 +18814,54 @@ public void PrimaryConstructors_21([CombinatorialValues("class", "struct")] stri
Diagnostic(RudeEditKind.Delete, keyword + " C", FeaturesResources.field));
}

[Fact]
public void PrimaryConstructors_22()
{
var src1 = "class C2(int x, int y) : C1(() => y) { void M() { x++; } } class C1(System.Func<int> x);";
var src2 = "class C2(int x, int y) : C1(() => x + y) { void M() { x++; } } class C1(System.Func<int> x);";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "class C2", FeaturesResources.class_));
}

[Fact]
public void PrimaryConstructors_23()
{
var src1 = "class C2(int x, int y) : C1(() => x + y) { void M() { x++; } } class C1(System.Func<int> x);";
var src2 = "class C2(int x, int y) : C1(() => y) { void M() { x++; } } class C1(System.Func<int> x);";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "class C2", FeaturesResources.class_));
}

[Fact]
public void PrimaryConstructors_24()
{
var src1 = "class C2(int x) : C1(null) { void M() { x++; } } class C1(System.Func<int> x);";
var src2 = "class C2(int x) : C1(() => x) { void M() { x++; } } class C1(System.Func<int> x);";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "class C2", FeaturesResources.class_));
}

[Fact]
public void PrimaryConstructors_25()
{
var src1 = "class C2(int x) : C1(() => x) { void M() { x++; } } class C1(System.Func<int> x);";
var src2 = "class C2(int x) : C1(null) { void M() { x++; } } class C1(System.Func<int> x);";

var edits = GetTopEdits(src1, src2);

edits.VerifySemanticDiagnostics(
Diagnostic(RudeEditKind.Update, "class C2", FeaturesResources.class_));
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,9 @@ protected override bool IsRudeEditDueToPrimaryConstructor(ISymbol symbol, Cancel
switch (symbol.Kind)
{
case SymbolKind.NamedType:
break;
{
return IsTypeWithPrimaryConstructor(symbol, cancellationToken);
}

case SymbolKind.Parameter:
{
Expand All @@ -3115,25 +3117,29 @@ protected override bool IsRudeEditDueToPrimaryConstructor(ISymbol symbol, Cancel

default:
{
var container = symbol.ContainingSymbol;
return IsTypeWithPrimaryConstructor(symbol.ContainingSymbol, cancellationToken);
}
}

return false;

if (container is { Kind: SymbolKind.NamedType, IsImplicitlyDeclared: false })
static bool IsTypeWithPrimaryConstructor(ISymbol container, CancellationToken cancellationToken)
{
if (container is { Kind: SymbolKind.NamedType, IsImplicitlyDeclared: false })
{
foreach (var syntaxReference in container.DeclaringSyntaxReferences)
{
if (syntaxReference.GetSyntax(cancellationToken) is
ClassDeclarationSyntax { ParameterList: not null } or
StructDeclarationSyntax { ParameterList: not null })
{
foreach (var syntaxReference in container.DeclaringSyntaxReferences)
{
if (syntaxReference.GetSyntax(cancellationToken) is
ClassDeclarationSyntax { ParameterList: not null } or
StructDeclarationSyntax { ParameterList: not null })
{
return true;
}
}
return true;
}
}
break;
}
}

return false;
return false;
}
}
}
}

0 comments on commit 461c28c

Please sign in to comment.