Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potentially ambiguous System.Object in _Imports.razor #10999

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -22,7 +22,7 @@ namespace Test
#nullable disable
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
#nullable restore
public partial class _Imports : System.Object
public partial class _Imports : object
#nullable disable
{
#pragma warning disable 219
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection
CSharpCode -
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
ClassDeclaration - - public partial - _Imports - System.Object -
ClassDeclaration - - public partial - _Imports - object -
DesignTimeDirective -
DirectiveToken - (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor) - MainLayout
CSharpCode -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Generated Location: (460:17,0 [23] )

Source Location: (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor)
|MainLayout|
Generated Location: (923:32,0 [10] )
Generated Location: (916:32,0 [10] )
|MainLayout|

Source Location: (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
|Foo|
Generated Location: (1356:49,6 [3] )
Generated Location: (1349:49,6 [3] )
|Foo|

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Test
;
[global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
#nullable restore
public partial class _Imports : System.Object
public partial class _Imports : object
#nullable disable
{
#pragma warning disable 1998
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection
CSharpCode -
IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))]
ClassDeclaration - - public partial - _Imports - System.Object -
ClassDeclaration - - public partial - _Imports - object -
MethodDeclaration - - protected - void - Execute
CSharpExpression - (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
LazyIntermediateToken - (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor) - CSharp - Foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Generated Location: (488:18,0 [23] )

Source Location: (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor)
|Foo|
Generated Location: (952:35,0 [3] )
Generated Location: (945:35,0 [3] )
|Foo|

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated(
{
// We don't want component imports to be considered as real component.
// But we still want to generate code for it so we can get diagnostics.
@class.BaseType = IntermediateToken.CreateCSharpToken(typeof(object).FullName);
@class.BaseType = IntermediateToken.CreateCSharpToken("object");

method.ReturnType = "void";
method.MethodName = "Execute";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ @using System.Net.Http
result.VerifyOutputsMatchBaseline();
}

[Fact]
public async Task ImportsRazor_SystemInNamespace()
{
// Arrange
var project = CreateTestProject(new()
{
["System/_Imports.razor"] = """
@using global::System.Net.Http
""",
});
var compilation = await project.GetCompilationAsync();
var driver = await GetDriverAsync(project);

// Act
var result = RunGenerator(compilation!, ref driver);

// Assert
result.Diagnostics.Verify();
Assert.Single(result.GeneratedSources);
result.VerifyOutputsMatchBaseline();
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/8718")]
public async Task PartialClass()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace MyApp.Folder1
#nullable disable
;
#nullable restore
public partial class _Imports : System.Object
public partial class _Imports : object
#nullable disable
{
#pragma warning disable 1998
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma checksum "System/_Imports.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "53b28fda6534c79c7b9a4da6dcc903c4b51cfab9"
// <auto-generated/>
#pragma warning disable 1591
namespace MyApp.System
{
#line default
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
#nullable restore
#line (1,2)-(1,31) "System/_Imports.razor"
using global::System.Net.Http

#line default
#line hidden
#nullable disable
;
#nullable restore
public partial class _Imports : object
#nullable disable
{
#pragma warning disable 1998
protected void Execute()
{
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace MyApp
#nullable disable
;
#nullable restore
public partial class _Imports : System.Object
public partial class _Imports : object
#nullable disable
{
#pragma warning disable 1998
Expand Down
Loading