diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs index a47706d2097f8..286c0e9633a5a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs @@ -3542,11 +3542,8 @@ private void AddSynthesizedRecordMembersIfNecessary(MembersAndInitializersBuilde addToStringMethod(printMembers); memberSignatures.Free(); -<<<<<<< HEAD fieldsByName.Free(); -======= memberNames.Free(); ->>>>>>> dotnet/main // We put synthesized record members first so that errors about conflicts show up on user-defined members rather than all // going to the record declaration @@ -3815,7 +3812,10 @@ ImmutableArray addProperties(ImmutableArray recordParam && field.TypeWithAnnotations.Equals(param.TypeWithAnnotations, TypeCompareKind.AllIgnoreOptions)) { Binder.CheckFeatureAvailability(syntax, MessageID.IDS_FeaturePositionalFieldsInRecords, diagnostics); - existingOrAddedMembers.Add(field); + if (!isInherited || checkMemberNotHidden(field, param)) + { + existingOrAddedMembers.Add(field); + } } else if (existingMember is PropertySymbol { IsStatic: false, GetMethod: { } } prop && prop.TypeWithAnnotations.Equals(param.TypeWithAnnotations, TypeCompareKind.AllIgnoreOptions)) diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs index a85a32a1d921e..bbd0abf92b8d1 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EditAndContinue/EditAndContinueTests.cs @@ -10667,13 +10667,15 @@ protected virtual bool PrintMembers(System.Text.StringBuilder builder) Row(21, TableIndex.TypeRef, EditAndContinueOperation.Default), Row(4, TableIndex.TypeSpec, EditAndContinueOperation.Default), Row(3, TableIndex.StandAloneSig, EditAndContinueOperation.Default), - Row(10, TableIndex.MethodDef, EditAndContinueOperation.Default)); // R.PrintMembers + Row(10, TableIndex.MethodDef, EditAndContinueOperation.Default), // R.PrintMembers + Row(24, TableIndex.CustomAttribute, EditAndContinueOperation.Default)); CheckEncMap(reader1, Handle(19, TableIndex.TypeRef), Handle(20, TableIndex.TypeRef), Handle(21, TableIndex.TypeRef), Handle(10, TableIndex.MethodDef), + Handle(24, TableIndex.CustomAttribute), Handle(3, TableIndex.StandAloneSig), Handle(4, TableIndex.TypeSpec), Handle(2, TableIndex.AssemblyRef)); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs index 470802dd46df4..03cd6ab2f818a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs @@ -28880,21 +28880,10 @@ public void SealedIncomplete() ); } -<<<<<<< HEAD - [Fact] - public void HiddenPositionalMember_Property() - { - var source = @" -var c = new C(0); -c.Deconstruct(out int i); -System.Console.Write(i); - -======= [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_HiddenWithZeroArityMethod() + public void HiddenPositionalMember_Property() { var source = @" ->>>>>>> dotnet/main public record Base { public int I { get; set; } = 42; @@ -28902,102 +28891,68 @@ public Base(int ignored) { } } public record C(int I) : Base(I) { -<<<<<<< HEAD public void I() { } // hiding } "; - // There should be an error because we pick a hidden member as a positional member - // This will be fixed in 16.10. Tracked by https://github.com/dotnet/roslyn/issues/52630 var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyDiagnostics( - // (13,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. + comp.VerifyEmitDiagnostics( + // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. + // public record C(int I) : Base(I) + Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), + // (9,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. // public void I() { } // hiding - Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(13, 17) + Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(9, 17) ); - - var verifier = CompileAndVerify(comp, expectedOutput: "42"); - verifier.VerifyIL("C.Deconstruct", @" -{ - // Code size 9 (0x9) - .maxstack 2 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: call ""int Base.I.get"" - IL_0007: stind.i4 - IL_0008: ret -} -"); } - [Fact] + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] public void HiddenPositionalMember_Field() { var source = @" -var c = new C(0); -c.Deconstruct(out int i); -System.Console.Write(i); - public record Base { public int I = 42; -======= - public void I() { } + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ + public void I() { } // hiding } "; - var expected = new[] - { + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics( // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. // public record C(int I) : Base(I) Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), // (9,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. - // public void I() { } + // public void I() { } // hiding Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(9, 17) - }; - - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular9); - comp.VerifyEmitDiagnostics(expected); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics(expected); + ); } [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_HiddenWithZeroArityMethod_DeconstructInSource() + public void HiddenPositionalMember_Field_HiddenWithConstant() { var source = @" public record Base { - public int I { get; set; } = 42; ->>>>>>> dotnet/main + public int I = 0; public Base(int ignored) { } } public record C(int I) : Base(I) { -<<<<<<< HEAD - public void I() { } // hiding + public const int I = 0; } "; - // There should be an error because we pick a hidden member as a positional member - // This will be fixed in 16.10. Tracked by https://github.com/dotnet/roslyn/issues/52630 var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyDiagnostics( - // (13,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. - // public void I() { } // hiding - Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(13, 17) + comp.VerifyEmitDiagnostics( + // (7,21): error CS8866: Record member 'C.I' must be a readable instance property or field of type 'int' to match positional parameter 'I'. + // public record C(int I) : Base(I) + Diagnostic(ErrorCode.ERR_BadRecordMemberForPositionalParameter, "I").WithArguments("C.I", "int", "I").WithLocation(7, 21), + // (9,22): warning CS0108: 'C.I' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. + // public const int I = 0; + Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I", "Base.I").WithLocation(9, 22) ); - - var verifier = CompileAndVerify(comp, expectedOutput: "42"); - verifier.VerifyIL("C.Deconstruct", @" -{ - // Code size 9 (0x9) - .maxstack 2 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: ldfld ""int Base.I"" - IL_0007: stind.i4 - IL_0008: ret -} -"); } [Fact] @@ -29168,123 +29123,11 @@ public void FieldAsPositionalMember_CurrentTypeComesFirst_FieldInBase() { var source = @" var c = new C(42); -======= - public void I() { } - public void Deconstruct(out int i) { i = 0; } -} -"; - var expected = new[] - { - // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. - // public record C(int I) : Base(I) - Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), - // (9,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. - // public void I() { } - Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(9, 17) - }; - - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular9); - comp.VerifyEmitDiagnostics(expected); - - comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics(expected); - } - - [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_HiddenWithZeroArityMethod_WithNew() - { - var source = @" -public record Base -{ - public int I { get; set; } = 42; - public Base(int ignored) { } -} -public record C(int I) : Base(I) // 1 -{ - public new void I() { } -} -"; - var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics( - // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. - // public record C(int I) : Base(I) // 1 - Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21) - ); - } - - [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_HiddenWithGenericMethod() - { - var source = @" -var c = new C(0); -c.Deconstruct(out int i); -System.Console.Write(i); - -public record Base -{ - public int I { get; set; } = 42; - public Base(int ignored) { } -} -public record C(int I) : Base(I) -{ - public void I() { } -} -"; - - var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics( - // (11,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. - // public record C(int I) : Base(I) - Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(11, 21), - // (13,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. - // public void I() { } - Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(13, 17) - ); - } - - [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_FromGrandBase() - { - var source = @" -public record GrandBase -{ - public int I { get; set; } = 42; -} -public record Base : GrandBase -{ - public Base(int ignored) { } -} -public record C(int I) : Base(I) -{ - public void I() { } -} -"; - var expected = new[] - { - // (10,21): error CS8913: The positional member 'GrandBase.I' found corresponding to this parameter is hidden. - // public record C(int I) : Base(I) - Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("GrandBase.I").WithLocation(10, 21), - // (12,17): warning CS0108: 'C.I()' hides inherited member 'GrandBase.I'. Use the new keyword if hiding was intended. - // public void I() { } - Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "GrandBase.I").WithLocation(12, 17) - }; - - var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics(expected); - } - - [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_NotHiddenByIndexer() - { - var source = @" -var c = new C(0); ->>>>>>> dotnet/main c.Deconstruct(out int i); System.Console.Write(i); public record Base { -<<<<<<< HEAD public int I = 0; } public record C(int I) : Base @@ -29298,19 +29141,6 @@ public record C(int I) : Base // public int I { get; set; } = I; Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I", "Base.I").WithLocation(12, 16) ); -======= - public int Item { get; set; } = 42; - public Base(int ignored) { } -} -public record C(int Item) : Base(Item) -{ - public int this[int x] { get => throw null; } -} -"; - - var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics(); ->>>>>>> dotnet/main var verifier = CompileAndVerify(comp, expectedOutput: "42"); verifier.VerifyIL("C.Deconstruct", @" @@ -29319,24 +29149,15 @@ public record C(int Item) : Base(Item) .maxstack 2 IL_0000: ldarg.1 IL_0001: ldarg.0 -<<<<<<< HEAD IL_0002: call ""int C.I.get"" -======= - IL_0002: call ""int Base.Item.get"" ->>>>>>> dotnet/main IL_0007: stind.i4 IL_0008: ret } "); } -<<<<<<< HEAD [Fact] public void FieldAsPositionalMember_FieldFromBase() -======= - [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_NotHiddenByIndexer_WithIndexerName() ->>>>>>> dotnet/main { var source = @" var c = new C(0); @@ -29345,29 +29166,15 @@ public void HiddenPositionalMember_Property_NotHiddenByIndexer_WithIndexerName() public record Base { -<<<<<<< HEAD public int I = 42; -======= - public int I { get; set; } = 42; ->>>>>>> dotnet/main public Base(int ignored) { } } public record C(int I) : Base(I) { -<<<<<<< HEAD } "; var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); comp.VerifyDiagnostics(); -======= - [System.Runtime.CompilerServices.IndexerName(""I"")] - public int this[int x] { get => throw null; } -} -"; - - var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics(); ->>>>>>> dotnet/main var verifier = CompileAndVerify(comp, expectedOutput: "42"); verifier.VerifyIL("C.Deconstruct", @" @@ -29376,38 +29183,24 @@ public record C(int I) : Base(I) .maxstack 2 IL_0000: ldarg.1 IL_0001: ldarg.0 -<<<<<<< HEAD IL_0002: ldfld ""int Base.I"" -======= - IL_0002: call ""int Base.I.get"" ->>>>>>> dotnet/main IL_0007: stind.i4 IL_0008: ret } "); } -<<<<<<< HEAD [Fact] public void FieldAsPositionalMember_FieldFromBase_StaticFieldInDerivedType() -======= - [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_HiddenWithType() ->>>>>>> dotnet/main { var source = @" public record Base { -<<<<<<< HEAD public int I = 42; -======= - public int I { get; set; } = 42; ->>>>>>> dotnet/main public Base(int ignored) { } } public record C(int I) : Base(I) { -<<<<<<< HEAD public static int I = 42; } "; @@ -29432,27 +29225,6 @@ public record C(int I) : Base(I) ); source = @" -======= - public class I { } -} -"; - - var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); - comp.VerifyEmitDiagnostics( - // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. - // public record C(int I) : Base(I) - Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), - // (9,18): warning CS0108: 'C.I' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. - // public class I { } - Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I", "Base.I").WithLocation(9, 18) - ); - } - - [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] - public void HiddenPositionalMember_Property_HiddenWithEvent() - { - var source = @" ->>>>>>> dotnet/main public record Base { public int I { get; set; } = 42; @@ -29460,7 +29232,6 @@ public Base(int ignored) { } } public record C(int I) : Base(I) { -<<<<<<< HEAD public static int I { get; set; } = 42; } "; @@ -29573,7 +29344,265 @@ record C(int P) // (2,14): error CS8866: Record member 'C.P' must be a readable instance property or field of type 'int' to match positional parameter 'P'. // record C(int P) Diagnostic(ErrorCode.ERR_BadRecordMemberForPositionalParameter, "P").WithArguments("C.P", "int", "P").WithLocation(2, 14) -======= + ); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_HiddenWithZeroArityMethod() + { + var source = @" +public record Base +{ + public int I { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ + public void I() { } +} +"; + var expected = new[] + { + // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. + // public record C(int I) : Base(I) + Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), + // (9,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. + // public void I() { } + Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(9, 17) + }; + + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular9); + comp.VerifyEmitDiagnostics(expected); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics(expected); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_HiddenWithZeroArityMethod_DeconstructInSource() + { + var source = @" +public record Base +{ + public int I { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ + public void I() { } + public void Deconstruct(out int i) { i = 0; } +} +"; + var expected = new[] + { + // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. + // public record C(int I) : Base(I) + Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), + // (9,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. + // public void I() { } + Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(9, 17) + }; + + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular9); + comp.VerifyEmitDiagnostics(expected); + + comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics(expected); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_HiddenWithZeroArityMethod_WithNew() + { + var source = @" +public record Base +{ + public int I { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int I) : Base(I) // 1 +{ + public new void I() { } +} +"; + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics( + // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. + // public record C(int I) : Base(I) // 1 + Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21) + ); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_HiddenWithGenericMethod() + { + var source = @" +var c = new C(0); +c.Deconstruct(out int i); +System.Console.Write(i); + +public record Base +{ + public int I { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ + public void I() { } +} +"; + + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics( + // (11,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. + // public record C(int I) : Base(I) + Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(11, 21), + // (13,17): warning CS0108: 'C.I()' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. + // public void I() { } + Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "Base.I").WithLocation(13, 17) + ); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_FromGrandBase() + { + var source = @" +public record GrandBase +{ + public int I { get; set; } = 42; +} +public record Base : GrandBase +{ + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ + public void I() { } +} +"; + var expected = new[] + { + // (10,21): error CS8913: The positional member 'GrandBase.I' found corresponding to this parameter is hidden. + // public record C(int I) : Base(I) + Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("GrandBase.I").WithLocation(10, 21), + // (12,17): warning CS0108: 'C.I()' hides inherited member 'GrandBase.I'. Use the new keyword if hiding was intended. + // public void I() { } + Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I()", "GrandBase.I").WithLocation(12, 17) + }; + + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics(expected); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_NotHiddenByIndexer() + { + var source = @" +var c = new C(0); +c.Deconstruct(out int i); +System.Console.Write(i); + +public record Base +{ + public int Item { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int Item) : Base(Item) +{ + public int this[int x] { get => throw null; } +} +"; + + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics(); + + var verifier = CompileAndVerify(comp, expectedOutput: "42"); + verifier.VerifyIL("C.Deconstruct", @" +{ + // Code size 9 (0x9) + .maxstack 2 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: call ""int Base.Item.get"" + IL_0007: stind.i4 + IL_0008: ret +} +"); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_NotHiddenByIndexer_WithIndexerName() + { + var source = @" +var c = new C(0); +c.Deconstruct(out int i); +System.Console.Write(i); + +public record Base +{ + public int I { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ + [System.Runtime.CompilerServices.IndexerName(""I"")] + public int this[int x] { get => throw null; } +} +"; + + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics(); + + var verifier = CompileAndVerify(comp, expectedOutput: "42"); + verifier.VerifyIL("C.Deconstruct", @" +{ + // Code size 9 (0x9) + .maxstack 2 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: call ""int Base.I.get"" + IL_0007: stind.i4 + IL_0008: ret +} +"); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_HiddenWithType() + { + var source = @" +public record Base +{ + public int I { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ + public class I { } +} +"; + + var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); + comp.VerifyEmitDiagnostics( + // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. + // public record C(int I) : Base(I) + Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), + // (9,18): warning CS0108: 'C.I' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. + // public class I { } + Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I", "Base.I").WithLocation(9, 18) + ); + } + + [Fact, WorkItem(52630, "https://github.com/dotnet/roslyn/issues/52630")] + public void HiddenPositionalMember_Property_HiddenWithEvent() + { + var source = @" +public record Base +{ + public int I { get; set; } = 42; + public Base(int ignored) { } +} +public record C(int I) : Base(I) +{ public event System.Action I; } "; @@ -29609,9 +29638,9 @@ public record C(int I) : Base(I) var comp = CreateCompilation(source, parseOptions: TestOptions.RegularPreview); comp.VerifyEmitDiagnostics( - // (7,21): error CS8913: The positional member 'Base.I' found corresponding to this parameter is hidden. + // (7,21): error CS8866: Record member 'C.I' must be a readable instance property or field of type 'int' to match positional parameter 'I'. // public record C(int I) : Base(I) - Diagnostic(ErrorCode.ERR_HiddenPositionalMember, "I").WithArguments("Base.I").WithLocation(7, 21), + Diagnostic(ErrorCode.ERR_BadRecordMemberForPositionalParameter, "I").WithArguments("C.I", "int", "I").WithLocation(7, 21), // (9,25): warning CS0108: 'C.I' hides inherited member 'Base.I'. Use the new keyword if hiding was intended. // public const string I = null; Diagnostic(ErrorCode.WRN_NewRequired, "I").WithArguments("C.I", "Base.I").WithLocation(9, 25) @@ -29663,7 +29692,6 @@ abstract record Derived(int I) : Base // (8,16): error CS0102: The type 'Derived' already contains a definition for 'I' // public int I() { return 0; } Diagnostic(ErrorCode.ERR_DuplicateNameInClass, "I").WithArguments("Derived", "I").WithLocation(8, 16) ->>>>>>> dotnet/main ); } } diff --git a/src/EditorFeatures/Core.Wpf/NavigateTo/NavigateToItemProvider.Callback.cs b/src/EditorFeatures/Core.Wpf/NavigateTo/NavigateToItemProvider.Callback.cs index c67a55b13977d..59d9b9a83a53f 100644 --- a/src/EditorFeatures/Core.Wpf/NavigateTo/NavigateToItemProvider.Callback.cs +++ b/src/EditorFeatures/Core.Wpf/NavigateTo/NavigateToItemProvider.Callback.cs @@ -66,53 +66,6 @@ private void ReportMatchResult(Project project, INavigateToSearchResult result) _callback.AddItem(navigateToItem); } -<<<<<<< HEAD - private static string GetKind(string kind) - => kind switch - { - CodeAnalysis.NavigateTo.NavigateToItemKind.Class - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Class, - CodeAnalysis.NavigateTo.NavigateToItemKind.Constant - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Constant, - CodeAnalysis.NavigateTo.NavigateToItemKind.Delegate - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Delegate, - CodeAnalysis.NavigateTo.NavigateToItemKind.Enum - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Enum, - CodeAnalysis.NavigateTo.NavigateToItemKind.EnumItem - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.EnumItem, - CodeAnalysis.NavigateTo.NavigateToItemKind.Event - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Event, - CodeAnalysis.NavigateTo.NavigateToItemKind.Field - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Field, - CodeAnalysis.NavigateTo.NavigateToItemKind.File - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.File, - CodeAnalysis.NavigateTo.NavigateToItemKind.Interface - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Interface, - CodeAnalysis.NavigateTo.NavigateToItemKind.Line - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Line, - CodeAnalysis.NavigateTo.NavigateToItemKind.Method - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Method, - CodeAnalysis.NavigateTo.NavigateToItemKind.Module - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Module, - CodeAnalysis.NavigateTo.NavigateToItemKind.OtherSymbol - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.OtherSymbol, - CodeAnalysis.NavigateTo.NavigateToItemKind.Property - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Property, - // VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind doesn't have a record, fall back to class. - // This should be updated whenever NavigateToItemKind has a record. - CodeAnalysis.NavigateTo.NavigateToItemKind.Record - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Class, - // VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind doesn't have a record struct, fall back to struct. - // This should be updated whenever NavigateToItemKind has a record struct. - CodeAnalysis.NavigateTo.NavigateToItemKind.RecordStruct - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Structure, - CodeAnalysis.NavigateTo.NavigateToItemKind.Structure - => VisualStudio.Language.NavigateTo.Interfaces.NavigateToItemKind.Structure, - _ => throw ExceptionUtilities.UnexpectedValue(kind) - }; - -======= ->>>>>>> dotnet/main private static PatternMatchKind GetPatternMatchKind(NavigateToMatchKind matchKind) => matchKind switch { diff --git a/src/EditorFeatures/Test2/IntelliSense/IntellisenseQuickInfoBuilderTests.vb b/src/EditorFeatures/Test2/IntelliSense/IntellisenseQuickInfoBuilderTests.vb index fb1193ca5e96d..ff0b631b560b1 100644 --- a/src/EditorFeatures/Test2/IntelliSense/IntellisenseQuickInfoBuilderTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/IntellisenseQuickInfoBuilderTests.vb @@ -1160,17 +1160,44 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense End Function -<<<<<<< HEAD - Public Async Function QuickInfoForRecordClass() As Task -======= Public Async Function QuickInfoForUnderlyingEnumTypes() As Task ->>>>>>> dotnet/main Dim workspace = -<<<<<<< HEAD + public enum E$$ : byte { A, B } + + + + + Dim intellisenseQuickInfo = Await GetQuickInfoItemAsync(workspace, LanguageNames.CSharp) + Assert.NotNull(intellisenseQuickInfo) + + Dim container = Assert.IsType(Of ContainerElement)(intellisenseQuickInfo.Item) + + Dim expected = New ContainerElement( + ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding, + New ContainerElement( + ContainerElementStyle.Wrapped, + New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.EnumerationPublic)), + New ClassifiedTextElement( + New ClassifiedTextRun(ClassificationTypeNames.Keyword, "enum"), + New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), + New ClassifiedTextRun(ClassificationTypeNames.EnumName, "E", navigationAction:=Sub() Return, "E"), + New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), + New ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), + New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), + New ClassifiedTextRun(ClassificationTypeNames.Keyword, "byte", navigationAction:=Sub() Return, "byte")))) + ToolTipAssert.EqualContent(expected, container) + End Function + + + Public Async Function QuickInfoForRecordClass() As Task + Dim workspace = + + + public sealed record class TestRecord(int X, int Y) { } class C @@ -1180,9 +1207,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense var x = new Test$$Record(1, 2); } } -======= - public enum E$$ : byte { A, B } ->>>>>>> dotnet/main @@ -1196,7 +1220,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense ContainerElementStyle.Stacked Or ContainerElementStyle.VerticalPadding, New ContainerElement( ContainerElementStyle.Wrapped, -<<<<<<< HEAD New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.MethodPublic)), New ClassifiedTextElement( New ClassifiedTextRun(ClassificationTypeNames.RecordClassName, "TestRecord", navigationAction:=Sub() Return, "TestRecord"), @@ -1267,17 +1290,6 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), New ClassifiedTextRun(ClassificationTypeNames.Text, FeaturesResources.overload), New ClassifiedTextRun(ClassificationTypeNames.Punctuation, ")")))) -======= - New ImageElement(New ImageId(KnownImageIds.ImageCatalogGuid, KnownImageIds.EnumerationPublic)), - New ClassifiedTextElement( - New ClassifiedTextRun(ClassificationTypeNames.Keyword, "enum"), - New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), - New ClassifiedTextRun(ClassificationTypeNames.EnumName, "E", navigationAction:=Sub() Return, "E"), - New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), - New ClassifiedTextRun(ClassificationTypeNames.Punctuation, ":"), - New ClassifiedTextRun(ClassificationTypeNames.WhiteSpace, " "), - New ClassifiedTextRun(ClassificationTypeNames.Keyword, "byte", navigationAction:=Sub() Return, "byte")))) ->>>>>>> dotnet/main ToolTipAssert.EqualContent(expected, container) End Function diff --git a/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs b/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs index 87b153273a981..de9ae560a58f4 100644 --- a/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs +++ b/src/Features/CSharp/Portable/EditAndContinue/SyntaxComparer.cs @@ -563,11 +563,7 @@ private static Label ClassifyTopSyntax(SyntaxKind kind, out bool isLeaf) case SyntaxKind.NamespaceDeclaration: return Label.NamespaceDeclaration; -<<<<<<< HEAD - // Need to add support for records (tracked by https://github.com/dotnet/roslyn/issues/44877) // Need to add support for record structs (tracked by https://github.com/dotnet/roslyn/issues/44877) -======= ->>>>>>> dotnet/main case SyntaxKind.ClassDeclaration: case SyntaxKind.StructDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -1347,11 +1343,7 @@ private static double CombineOptional( case SyntaxKind.NamespaceDeclaration: return ((NamespaceDeclarationSyntax)node).Name; -<<<<<<< HEAD - // Need to add support for records (tracked by https://github.com/dotnet/roslyn/issues/44877) // Need to add support for record structs (tracked by https://github.com/dotnet/roslyn/issues/44877) -======= ->>>>>>> dotnet/main case SyntaxKind.ClassDeclaration: case SyntaxKind.StructDeclaration: case SyntaxKind.InterfaceDeclaration: diff --git a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs index 9d1bd8dde8db4..1e50843a2a20e 100644 --- a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs +++ b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.InProcess.cs @@ -288,13 +288,9 @@ private static string GetItemKind(DeclaredSymbolInfo declaredSymbolInfo) { case DeclaredSymbolInfoKind.Class: case DeclaredSymbolInfoKind.Record: -<<<<<<< HEAD - return NavigateToItemKind.Record; - case DeclaredSymbolInfoKind.RecordStruct: - return NavigateToItemKind.RecordStruct; -======= return NavigateToItemKind.Class; ->>>>>>> dotnet/main + case DeclaredSymbolInfoKind.RecordStruct: + return NavigateToItemKind.Structure; case DeclaredSymbolInfoKind.Constant: return NavigateToItemKind.Constant; case DeclaredSymbolInfoKind.Delegate: @@ -363,9 +359,6 @@ public DeclaredSymbolInfoKindSet(IEnumerable navigateToItemKinds) lookupTable[(int)DeclaredSymbolInfoKind.Class] = true; lookupTable[(int)DeclaredSymbolInfoKind.Record] = true; break; - case NavigateToItemKind.RecordStruct: - lookupTable[(int)DeclaredSymbolInfoKind.RecordStruct] = true; - break; case NavigateToItemKind.Constant: lookupTable[(int)DeclaredSymbolInfoKind.Constant] = true; break; @@ -411,6 +404,7 @@ public DeclaredSymbolInfoKindSet(IEnumerable navigateToItemKinds) case NavigateToItemKind.Structure: lookupTable[(int)DeclaredSymbolInfoKind.Struct] = true; + lookupTable[(int)DeclaredSymbolInfoKind.RecordStruct] = true; break; default: diff --git a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.cs b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.cs index a402bad781392..7f77e87431778 100644 --- a/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.cs +++ b/src/Features/Core/Portable/NavigateTo/AbstractNavigateToSearchService.cs @@ -16,11 +16,6 @@ internal abstract partial class AbstractNavigateToSearchService : INavigateToSea { public IImmutableSet KindsProvided { get; } = ImmutableHashSet.Create( NavigateToItemKind.Class, -<<<<<<< HEAD - NavigateToItemKind.Record, - NavigateToItemKind.RecordStruct, -======= ->>>>>>> dotnet/main NavigateToItemKind.Constant, NavigateToItemKind.Delegate, NavigateToItemKind.Enum, diff --git a/src/Features/Core/Portable/NavigateTo/NavigateToItemKind.cs b/src/Features/Core/Portable/NavigateTo/NavigateToItemKind.cs index a4373967a2a9b..8790ecb998ca8 100644 --- a/src/Features/Core/Portable/NavigateTo/NavigateToItemKind.cs +++ b/src/Features/Core/Portable/NavigateTo/NavigateToItemKind.cs @@ -11,11 +11,6 @@ internal static class NavigateToItemKind public const string Line = nameof(Line); public const string File = nameof(File); public const string Class = nameof(Class); -<<<<<<< HEAD - public const string Record = nameof(Record); - public const string RecordStruct = nameof(RecordStruct); -======= ->>>>>>> dotnet/main public const string Structure = nameof(Structure); public const string Interface = nameof(Interface); public const string Delegate = nameof(Delegate); diff --git a/src/Tools/ExternalAccess/FSharp/NavigateTo/FSharpNavigateToItemKind.cs b/src/Tools/ExternalAccess/FSharp/NavigateTo/FSharpNavigateToItemKind.cs index 570199cda21d9..123c14ebb4baa 100644 --- a/src/Tools/ExternalAccess/FSharp/NavigateTo/FSharpNavigateToItemKind.cs +++ b/src/Tools/ExternalAccess/FSharp/NavigateTo/FSharpNavigateToItemKind.cs @@ -13,11 +13,6 @@ internal static class FSharpNavigateToItemKind public static string Line => NavigateToItemKind.Line; public static string File = NavigateToItemKind.File; public static string Class => NavigateToItemKind.Class; -<<<<<<< HEAD - public static string Record => NavigateToItemKind.Record; - public static string RecordStruct => NavigateToItemKind.RecordStruct; -======= ->>>>>>> dotnet/main public static string Structure => NavigateToItemKind.Structure; public static string Interface => NavigateToItemKind.Interface; public static string Delegate => NavigateToItemKind.Delegate;