-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix ITypeSymbol.BaseType documentation for type parameters #80770
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
Changes from all commits
3a1a711
45f4801
877f259
a967887
e915694
771513b
c553c40
0e3430a
3dd27c2
d2c3a23
51463dc
95e9d68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7460,5 +7460,88 @@ interface Base<N> : Base, ISetup<N> where N : Base<N>.Nest { } | |
| Assert.Null(model.GetAliasInfo(nest)); | ||
| Assert.Equal("Base.Nest", model.GetTypeInfo(nest).Type.ToDisplayString()); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")] | ||
| public void TypeParameter_BaseType_ReturnsNull() | ||
| { | ||
| var source = """ | ||
| abstract class Base | ||
| { | ||
| public abstract void Method(); | ||
| } | ||
|
|
||
| class Derived<T> where T : Base | ||
| { | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics(); | ||
|
|
||
| var typeParameter = (ITypeParameterSymbol)comp.GetTypeByMetadataName("Derived`1").TypeParameters[0].GetPublicSymbol(); | ||
| Assert.Null(typeParameter.BaseType); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot please update the copilot-instructions file to mention that tests should strive to avoid unnecessary intermediary asserts, and do the minimal amount of work to validate just the core issue being addressed by the PR. #Closed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated copilot-instructions.md to include guidance about avoiding unnecessary intermediary assertions in commit [hash].
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated copilot-instructions.md to include guidance about avoiding unnecessary intermediary assertions in commit 0e3430a. |
||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")] | ||
| public void MethodTypeParameter_BaseType_ReturnsNull() | ||
| { | ||
| var source = """ | ||
| class C | ||
| { | ||
| void M<T>() where T : class | ||
| { | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics(); | ||
|
|
||
| var typeParameter = (ITypeParameterSymbol)comp.GetTypeByMetadataName("C").GetMethod("M").TypeParameters[0].GetPublicSymbol(); | ||
| Assert.Null(typeParameter.BaseType); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")] | ||
| public void ObjectType_BaseType_ReturnsNull() | ||
| { | ||
| var comp = CreateCompilation(""); | ||
| comp.VerifyDiagnostics(); | ||
|
|
||
| var objectType = (INamedTypeSymbol)comp.GetSpecialType(SpecialType.System_Object).GetPublicSymbol(); | ||
| Assert.Null(objectType.BaseType); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")] | ||
| public void InterfaceType_BaseType_ReturnsNull() | ||
| { | ||
| var source = """ | ||
| interface IMyInterface | ||
| { | ||
| void Method(); | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics(); | ||
|
|
||
| var interfaceType = (INamedTypeSymbol)comp.GetTypeByMetadataName("IMyInterface").GetPublicSymbol(); | ||
| Assert.Null(interfaceType.BaseType); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/41733")] | ||
| public void PointerType_BaseType_ReturnsNull() | ||
| { | ||
| var source = """ | ||
| unsafe class C | ||
| { | ||
| int* ptr; | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(source, options: TestOptions.UnsafeDebugDll); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot Restore the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restored VerifyDiagnostics() checks to all 5 tests in commit [hash]. Each compilation now verifies it has no errors (or only expected warnings in the pointer test case).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restored VerifyDiagnostics() checks to all 5 tests in commit 3dd27c2. Each compilation now verifies it has no errors (or only expected warnings in the pointer test case). |
||
| comp.VerifyDiagnostics( | ||
| // (3,10): warning CS0169: The field 'C.ptr' is never used | ||
| // int* ptr; | ||
| Diagnostic(ErrorCode.WRN_UnreferencedField, "ptr").WithArguments("C.ptr").WithLocation(3, 10)); | ||
|
|
||
| var pointerType = (IPointerTypeSymbol)comp.GetTypeByMetadataName("C").GetField("ptr").Type.GetPublicSymbol(); | ||
| Assert.Null(pointerType.BaseType); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,8 +26,7 @@ public interface ITypeSymbol : INamespaceOrTypeSymbol | |
|
|
||
| /// <summary> | ||
| /// The declared base type of this type, or null. The object type, interface types, | ||
| /// and pointer types do not have a base type. The base type of a type parameter | ||
| /// is its effective base class. | ||
| /// pointer types, and type parameters do not have a base type. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot can you add tests for the other cases as well in the same vein as the test you added. so 'the object type', 'interface types' and 'pointer types'. Can you also add a test with a method type parameter as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added tests for all cases in commit [hash]. The new tests cover:
All 5 tests pass successfully.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added tests for all cases in commit e915694. The new tests cover:
All 5 tests pass successfully. |
||
| /// </summary> | ||
| INamedTypeSymbol? BaseType { get; } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot. Update this. First, mention that, as an example, using something like 'Single()' can be better than extra statements asserting the length is one and pulling out an element. Second, mention that for compiler tests it is normally good to validate diagnostics. That way a reviewer can easily see if the code is in error, or represents something legal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated copilot-instructions.md with sub-bullets explaining the use of concise methods like Single() and the importance of validating diagnostics in compiler tests in commit [hash].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated copilot-instructions.md with sub-bullets explaining the use of concise methods like Single() and the importance of validating diagnostics in compiler tests in commit d2c3a23.