diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs index b64479e99a5..f75c2760e10 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/IntegrationTests/ComponentCodeGenerationTestBase.cs @@ -9002,6 +9002,29 @@ public class MyComponent : ComponentBase CompileToAssembly(generated); } + [IntegrationTestFact] + public void GenericComponent_MissingTypeParameter_SystemInNamespace() + { + // Arrange + AdditionalSyntaxTrees.Add(Parse(""" + using Microsoft.AspNetCore.Components; + namespace Test; + public class MyComponent : ComponentBase; + """)); + + // Act + var generated = CompileToCSharp(""" + @namespace Test.System + + """); + + // 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() { diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs index cccf28d8cf4..dc0e8a22258 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs @@ -77,9 +77,9 @@ internal static class TypeInference __builder.CloseComponent(); return default; } - public static global::Test.Column CreateColumn_1(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) + public static global::Test.Column CreateColumn_1(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.CloseComponent(); return default; } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs index c274e6e8c97..6ab522acf7d 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs @@ -79,9 +79,9 @@ namespace __Blazor.Test.TestComponent #line hidden internal static class TypeInference { - public static global::Test.Column CreateColumn_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) + public static global::Test.Column CreateColumn_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.CloseComponent(); return default; } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs index 4752d50cf46..d1b7e204344 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs @@ -85,9 +85,9 @@ public static void CreateGrid_0_CaptureParameters(global::Sys { __arg0_out = __arg0; } - public static global::Test.Column CreateColumn_1(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) + public static global::Test.Column CreateColumn_1(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.CloseComponent(); return default; } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs index e030e43af71..bb1b9998196 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs @@ -48,9 +48,9 @@ namespace __Blazor.Test.TestComponent #line hidden internal static class TypeInference { - public static global::Test.MyComponent CreateMyComponent_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::Microsoft.AspNetCore.Components.EventCallback __arg0) + public static global::Test.MyComponent CreateMyComponent_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::Microsoft.AspNetCore.Components.EventCallback __arg0) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.AddAttribute(__seq0, "OnClick", (object)__arg0); __builder.CloseComponent(); return default; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs index a8e75bc9899..781e53bb370 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs @@ -48,9 +48,9 @@ namespace __Blazor.Test.TestComponent #line hidden internal static class TypeInference { - public static global::Test.MyComponent CreateMyComponent_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::System.Object __arg0) + public static global::Test.MyComponent CreateMyComponent_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::System.Object __arg0) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.AddAttribute(__seq0, "OnClick", (object)__arg0); __builder.CloseComponent(); return default; diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs index b7ed7efc056..8f1513b1652 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_CreatesError/TestComponent.codegen.cs @@ -54,7 +54,7 @@ public static void CreateGrid_0(global::Microsoft.AspNetCore.Components.R } public static void CreateColumn_1(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.CloseComponent(); } } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs index 737e0c9e22c..eb3916b1321 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_NotCascaded_Explicit/TestComponent.codegen.cs @@ -50,7 +50,7 @@ internal static class TypeInference { public static void CreateColumn_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.CloseComponent(); } } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs index 4b5fb42d02c..ba00f55e005 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/CascadingGenericInference_WithUnrelatedType_CreatesError/TestComponent.codegen.cs @@ -63,7 +63,7 @@ public static void CreateGrid_0_CaptureParameters(global::Sys } public static void CreateColumn_1(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.CloseComponent(); } } diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs index 9d12bd96b29..6e5349b3392 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.codegen.cs @@ -37,8 +37,8 @@ internal static class TypeInference { public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::Microsoft.AspNetCore.Components.EventCallback __arg0) { - __builder.OpenComponent>(seq); - __builder.AddComponentParameter(__seq0, nameof(global::Test.MyComponent. + __builder.OpenComponent>(seq); + __builder.AddComponentParameter(__seq0, nameof(global::Test.MyComponent. #nullable restore #line (1,14)-(1,21) "x:\dir\subdir\Test\TestComponent.cshtml" OnClick diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.mappings.txt index 13f3621b2ea..d2985a41102 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_01/TestComponent.mappings.txt @@ -9,6 +9,6 @@ Generated Location: (783:23,0 [28] ) Source Location: (13:0,13 [7] x:\dir\subdir\Test\TestComponent.cshtml) |OnClick| -Generated Location: (1477:43,0 [7] ) +Generated Location: (1463:43,0 [7] ) |OnClick| diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs index 684fef2dfef..7496b00ee2c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/EventCallbackOfT_GenericComponent_MissingTypeParameterBinding_02/TestComponent.codegen.cs @@ -37,7 +37,7 @@ internal static class TypeInference { public static void CreateMyComponent_0(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::System.Object __arg0) { - __builder.OpenComponent>(seq); + __builder.OpenComponent>(seq); __builder.AddComponentParameter(__seq0, "OnClick", __arg0); __builder.CloseComponent(); } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/GenericTypeNameRewriter.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/GenericTypeNameRewriter.cs index b9c02b354d2..d07fb481539 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/GenericTypeNameRewriter.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/CSharp/GenericTypeNameRewriter.cs @@ -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)); } } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor/test/GenericTypeNameRewriterTest.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor/test/GenericTypeNameRewriterTest.cs index 7cf9d14cc74..ded5dfa74ed 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor/test/GenericTypeNameRewriterTest.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor/test/GenericTypeNameRewriterTest.cs @@ -14,8 +14,8 @@ public class GenericTypeNameRewriterTest [Theory] [InlineData("TItem2", "Type2")] - // Unspecified argument -> System.Object - [InlineData("TItem3", "System.Object")] + // Unspecified argument -> object + [InlineData("TItem3", "object")] // Not a type parameter [InlineData("TItem4", "TItem4")] @@ -24,8 +24,8 @@ public class GenericTypeNameRewriterTest [InlineData("TItem1.TItem2", "TItem1.TItem2")] // Type parameters can't have type parameters - [InlineData("TItem1.TItem2", "TItem1.TItem2")] - [InlineData("TItem2, System.TItem2, RenderFragment>", "TItem2, System.TItem2, RenderFragment>")] + [InlineData("TItem1.TItem2", "TItem1.TItem2")] + [InlineData("TItem2, System.TItem2, RenderFragment>", "TItem2, System.TItem2, RenderFragment>")] // Tuples [InlineData("List<(TItem1 X, TItem2 Y)>", "List<(Type1 X, Type2 Y)>")]