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

Disable EnC for more Primary Constructors scenarios #67026

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 @@ -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;
}
}
}
}