Skip to content

Commit

Permalink
Avoid ambiguous object reference in generic component recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Oct 21, 2024
1 parent a91bdcc commit 39333ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9002,6 +9002,29 @@ public class MyComponent<TService, TKey> : ComponentBase
CompileToAssembly(generated);
}

[IntegrationTestFact]
public void GenericComponent_MissingTypeParameter_SystemInNamespace()
{
// Arrange
AdditionalSyntaxTrees.Add(Parse("""
using Microsoft.AspNetCore.Components;
namespace Test;
public class MyComponent<TItem> : ComponentBase;
"""));

// Act
var generated = CompileToCSharp("""
@namespace Test.System
<MyComponent />
""");

// Assert
CompileToAssembly(generated);
generated.RazorDiagnostics.Verify(
// x:\dir\subdir\Test\TestComponent.cshtml(2,1): error RZ10001: The type of component 'MyComponent' cannot be inferred based on the values provided. Consider specifying the type arguments directly using the following attributes: 'TItem'.
Diagnostic("RZ10001").WithLocation(2, 1));
}

[IntegrationTestFact, WorkItem("https://github.com/dotnet/razor/issues/10827")]
public void GenericTypeCheck()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override SyntaxNode Visit(SyntaxNode node)
// compared to leaving the type parameter in place.
//
// We add our own diagnostics for missing/invalid type parameters anyway.
var replacement = binding == null ? typeof(object).FullName : binding;
var replacement = binding ?? "object";
return identifier.Update(SyntaxFactory.Identifier(replacement).WithTriviaFrom(identifier.Identifier));
}
}
Expand Down

0 comments on commit 39333ab

Please sign in to comment.