Skip to content

Commit faba442

Browse files
authored
Fix potentially ambiguous System.Object in _Imports.razor (#10999)
* Add a test * Fix potentially ambiguous System.Object in _Imports.razor * Update baselines
1 parent ecb4434 commit faba442

File tree

11 files changed

+63
-10
lines changed

11 files changed

+63
-10
lines changed

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Test
2222
#nullable disable
2323
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
2424
#nullable restore
25-
public partial class _Imports : System.Object
25+
public partial class _Imports : object
2626
#nullable disable
2727
{
2828
#pragma warning disable 219

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.ir.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection
1010
CSharpCode -
1111
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
12-
ClassDeclaration - - public partial - _Imports - System.Object -
12+
ClassDeclaration - - public partial - _Imports - object -
1313
DesignTimeDirective -
1414
DirectiveToken - (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor) - MainLayout
1515
CSharpCode -

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ Generated Location: (460:17,0 [23] )
1010

1111
Source Location: (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor)
1212
|MainLayout|
13-
Generated Location: (923:32,0 [10] )
13+
Generated Location: (916:32,0 [10] )
1414
|MainLayout|
1515

1616
Source Location: (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
1717
|Foo|
18-
Generated Location: (1356:49,6 [3] )
18+
Generated Location: (1349:49,6 [3] )
1919
|Foo|
2020

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace Test
2424
;
2525
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
2626
#nullable restore
27-
public partial class _Imports : System.Object
27+
public partial class _Imports : object
2828
#nullable disable
2929
{
3030
#pragma warning disable 1998

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.ir.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection
1010
CSharpCode -
1111
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
12-
ClassDeclaration - - public partial - _Imports - System.Object -
12+
ClassDeclaration - - public partial - _Imports - object -
1313
MethodDeclaration - - protected - void - Execute
1414
CSharpExpression - (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
1515
LazyIntermediateToken - (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor) - CSharp - Foo

src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Generated Location: (488:18,0 [23] )
1010

1111
Source Location: (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
1212
|Foo|
13-
Generated Location: (952:35,0 [3] )
13+
Generated Location: (945:35,0 [3] )
1414
|Foo|
1515

src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated(
9999
{
100100
// We don't want component imports to be considered as real component.
101101
// But we still want to generate code for it so we can get diagnostics.
102-
@class.BaseType = IntermediateToken.CreateCSharpToken(typeof(object).FullName);
102+
@class.BaseType = IntermediateToken.CreateCSharpToken("object");
103103

104104
method.ReturnType = "void";
105105
method.MethodName = "Execute";

src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorComponentTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,28 @@ @using System.Net.Http
7676
result.VerifyOutputsMatchBaseline();
7777
}
7878

79+
[Fact]
80+
public async Task ImportsRazor_SystemInNamespace()
81+
{
82+
// Arrange
83+
var project = CreateTestProject(new()
84+
{
85+
["System/_Imports.razor"] = """
86+
@using global::System.Net.Http
87+
""",
88+
});
89+
var compilation = await project.GetCompilationAsync();
90+
var driver = await GetDriverAsync(project);
91+
92+
// Act
93+
var result = RunGenerator(compilation!, ref driver);
94+
95+
// Assert
96+
result.Diagnostics.Verify();
97+
Assert.Single(result.GeneratedSources);
98+
result.VerifyOutputsMatchBaseline();
99+
}
100+
79101
[Fact, WorkItem("https://github.com/dotnet/razor/issues/8718")]
80102
public async Task PartialClass()
81103
{

src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor/Folder1__Imports_razor.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace MyApp.Folder1
1818
#nullable disable
1919
;
2020
#nullable restore
21-
public partial class _Imports : System.Object
21+
public partial class _Imports : object
2222
#nullable disable
2323
{
2424
#pragma warning disable 1998
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma checksum "System/_Imports.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "53b28fda6534c79c7b9a4da6dcc903c4b51cfab9"
2+
// <auto-generated/>
3+
#pragma warning disable 1591
4+
namespace MyApp.System
5+
{
6+
#line default
7+
using global::System;
8+
using global::System.Collections.Generic;
9+
using global::System.Linq;
10+
using global::System.Threading.Tasks;
11+
using global::Microsoft.AspNetCore.Components;
12+
#nullable restore
13+
#line (1,2)-(1,31) "System/_Imports.razor"
14+
using global::System.Net.Http
15+
16+
#line default
17+
#line hidden
18+
#nullable disable
19+
;
20+
#nullable restore
21+
public partial class _Imports : object
22+
#nullable disable
23+
{
24+
#pragma warning disable 1998
25+
protected void Execute()
26+
{
27+
}
28+
#pragma warning restore 1998
29+
}
30+
}
31+
#pragma warning restore 1591

src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_WithMarkup/_Imports_razor.g.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace MyApp
1818
#nullable disable
1919
;
2020
#nullable restore
21-
public partial class _Imports : System.Object
21+
public partial class _Imports : object
2222
#nullable disable
2323
{
2424
#pragma warning disable 1998

0 commit comments

Comments
 (0)