Skip to content

Commit

Permalink
Fix error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson committed Apr 18, 2024
1 parent 5c472ca commit 8dba532
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 40 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3604,7 +3604,7 @@ private void MergePartialMembers(
break;

case (SourcePropertyAccessorSymbol, SourcePropertyAccessorSymbol):
continue; // accessor symbols and their diagnostics are handled by processing the associated property
break; // accessor symbols and their diagnostics are handled by processing the associated property

default:
throw ExceptionUtilities.UnexpectedValue(prev);
Expand Down Expand Up @@ -3679,14 +3679,12 @@ void mergePartialProperties(ref Dictionary<ReadOnlyMemory<char>, ImmutableArray<
if (currentProperty.IsPartialImplementation &&
(prevProperty.IsPartialImplementation || (prevProperty.OtherPartOfPartial is SourcePropertySymbol otherImplementation && (object)otherImplementation != currentProperty)))
{
// A partial method may not have multiple implementing declarations
diagnostics.Add(ErrorCode.ERR_PartialMethodOnlyOneActual, currentProperty.GetFirstLocation());
diagnostics.Add(ErrorCode.ERR_PartialPropertyDuplicateImplementation, currentProperty.GetFirstLocation());
}
else if (currentProperty.IsPartialDefinition &&
(prevProperty.IsPartialDefinition || (prevProperty.OtherPartOfPartial is SourcePropertySymbol otherDefinition && (object)otherDefinition != currentProperty)))
{
// A partial method may not have multiple defining declarations
diagnostics.Add(ErrorCode.ERR_PartialMethodOnlyOneLatent, currentProperty.GetFirstLocation());
diagnostics.Add(ErrorCode.ERR_PartialPropertyDuplicateDefinition, currentProperty.GetFirstLocation());
}
else
{
Expand Down
26 changes: 14 additions & 12 deletions src/Compilers/CSharp/Test/Symbol/Symbols/PartialPropertiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ partial class C
// (3,17): error CS9300: Partial property 'C.P' must have an implementation part.
// partial int P { get; set; }
Diagnostic(ErrorCode.ERR_PartialPropertyMissingImplementation, "P").WithArguments("C.P").WithLocation(3, 17),
// (4,17): error CS0756: A partial method may not have multiple defining declarations
// (4,17): error CS9302: A partial property may not have multiple defining declarations
// partial int P { get; set; }
Diagnostic(ErrorCode.ERR_PartialMethodOnlyOneLatent, "P").WithLocation(4, 17),
Diagnostic(ErrorCode.ERR_PartialPropertyDuplicateDefinition, "P").WithLocation(4, 17),
// (4,17): error CS0102: The type 'C' already contains a definition for 'P'
// partial int P { get; set; }
Diagnostic(ErrorCode.ERR_DuplicateNameInClass, "P").WithArguments("C", "P").WithLocation(4, 17)
Expand All @@ -100,9 +100,9 @@ partial class C
""";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics(
// (4,17): error CS0756: A partial method may not have multiple defining declarations
// (4,17): error CS9302: A partial property may not have multiple defining declarations
// partial int P { get; set; }
Diagnostic(ErrorCode.ERR_PartialMethodOnlyOneLatent, "P").WithLocation(4, 17),
Diagnostic(ErrorCode.ERR_PartialPropertyDuplicateDefinition, "P").WithLocation(4, 17),
// (4,17): error CS0102: The type 'C' already contains a definition for 'P'
// partial int P { get; set; }
Diagnostic(ErrorCode.ERR_DuplicateNameInClass, "P").WithArguments("C", "P").WithLocation(4, 17)
Expand All @@ -125,9 +125,9 @@ partial class C
// (3,17): error CS9301: Partial property 'C.P' must have an definition part.
// partial int P { get => throw null!; set { } }
Diagnostic(ErrorCode.ERR_PartialPropertyMissingDefinition, "P").WithArguments("C.P").WithLocation(3, 17),
// (4,17): error CS0757: A partial method may not have multiple implementing declarations
// (4,17): error CS9303: A partial property may not have multiple implementing declarations
// partial int P { get => throw null!; set { } }
Diagnostic(ErrorCode.ERR_PartialMethodOnlyOneActual, "P").WithLocation(4, 17),
Diagnostic(ErrorCode.ERR_PartialPropertyDuplicateImplementation, "P").WithLocation(4, 17),
// (4,17): error CS0102: The type 'C' already contains a definition for 'P'
// partial int P { get => throw null!; set { } }
Diagnostic(ErrorCode.ERR_DuplicateNameInClass, "P").WithArguments("C", "P").WithLocation(4, 17)
Expand All @@ -148,9 +148,9 @@ partial class C
""";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics(
// (5,17): error CS0757: A partial method may not have multiple implementing declarations
// (5,17): error CS9303: A partial property may not have multiple implementing declarations
// partial int P { get => throw null!; set { } }
Diagnostic(ErrorCode.ERR_PartialMethodOnlyOneActual, "P").WithLocation(5, 17),
Diagnostic(ErrorCode.ERR_PartialPropertyDuplicateImplementation, "P").WithLocation(5, 17),
// (5,17): error CS0102: The type 'C' already contains a definition for 'P'
// partial int P { get => throw null!; set { } }
Diagnostic(ErrorCode.ERR_DuplicateNameInClass, "P").WithArguments("C", "P").WithLocation(5, 17)
Expand All @@ -172,15 +172,15 @@ partial class C
""";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics(
// (4,17): error CS0756: A partial method may not have multiple defining declarations
// (4,17): error CS9302: A partial property may not have multiple defining declarations
// partial int P { get; set; }
Diagnostic(ErrorCode.ERR_PartialMethodOnlyOneLatent, "P").WithLocation(4, 17),
Diagnostic(ErrorCode.ERR_PartialPropertyDuplicateDefinition, "P").WithLocation(4, 17),
// (4,17): error CS0102: The type 'C' already contains a definition for 'P'
// partial int P { get; set; }
Diagnostic(ErrorCode.ERR_DuplicateNameInClass, "P").WithArguments("C", "P").WithLocation(4, 17),
// (6,17): error CS0757: A partial method may not have multiple implementing declarations
// (6,17): error CS9303: A partial property may not have multiple implementing declarations
// partial int P { get => throw null!; set { } }
Diagnostic(ErrorCode.ERR_PartialMethodOnlyOneActual, "P").WithLocation(6, 17),
Diagnostic(ErrorCode.ERR_PartialPropertyDuplicateImplementation, "P").WithLocation(6, 17),
// (6,17): error CS0102: The type 'C' already contains a definition for 'P'
// partial int P { get => throw null!; set { } }
Diagnostic(ErrorCode.ERR_DuplicateNameInClass, "P").WithArguments("C", "P").WithLocation(6, 17)
Expand Down Expand Up @@ -403,5 +403,7 @@ partial class C
}

// PROTOTYPE(partial-properties): test more mismatching scenarios
// PROTOTYPE(partial-properties): test indexers incl parameters with attributes
// PROTOTYPE(partial-properties): test merging property attributes
}
}

0 comments on commit 8dba532

Please sign in to comment.