Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -7460,5 +7460,34 @@ 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/78605")]

@CyrusNajmabadi CyrusNajmabadi Oct 20, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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.

public void TypeParameter_BaseType_ReturnsNull()
{
// This test verifies that ITypeSymbol.BaseType returns null for type parameters,
// not the effective base class.
var source = @"

@CyrusNajmabadi CyrusNajmabadi Oct 16, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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.

abstract class Base
{
public abstract void Method();
}

class Derived<T> where T : Base
{
}";
var comp = CreateCompilation(source);
comp.VerifyDiagnostics();

var derivedType = comp.GetTypeByMetadataName("Derived`1");
Assert.NotNull(derivedType);

@jcouv jcouv Oct 20, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The tests are unnecessarily verbose. There's no benefit to those intermediary assertions. There's only one thing this test is intended to check, the final assertion in the test. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot simplify the tests to remove all intermediary assertions and just do the minimum necessary to accomplish the Assert.NotNull(....BaseType) check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified all 5 tests to remove intermediary assertions in commit [hash]. Each test now only contains the minimal code necessary to perform the Assert.Null(BaseType) check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified all 5 tests to remove intermediary assertions in commit c553c40. Each test now only contains the minimal code necessary to perform the Assert.Null(BaseType) check.


var typeParameter = derivedType.TypeParameters[0];
Assert.NotNull(typeParameter);

// Test the public API: ITypeSymbol.BaseType should return null for type parameters,
// even though there is an effective base class (Base in this case).
var publicTypeParameter = (ITypeParameterSymbol)typeParameter.GetPublicSymbol();
Assert.Null(publicTypeParameter.BaseType);
}
}
}
3 changes: 1 addition & 2 deletions src/Compilers/Core/Portable/Symbols/ITypeSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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.

/// </summary>
INamedTypeSymbol? BaseType { get; }

Expand Down
Loading