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

Generator incorrectly prefixes relative namespaced types with global:: #8610

Closed
chsienki opened this issue Apr 19, 2023 · 3 comments · Fixed by #8614
Closed

Generator incorrectly prefixes relative namespaced types with global:: #8610

chsienki opened this issue Apr 19, 2023 · 3 comments · Fixed by #8614
Assignees
Labels
area-compiler Umbrella for all compiler issues bug Something isn't working

Comments

@chsienki
Copy link
Contributor

See dotnet/aspnetcore#47540

There is an alias @using WeatherForecast = Pages.GridRendering.WeatherForecast where the Pages namespace is relative to the containing namespace (I.e., not at the root)

We're incorrectly code-genning global::Pages.GridRendering.WeatherForecast which is not valid; we should either leave it relative or add in the full namespace of the type.

@chsienki chsienki added bug Something isn't working area-compiler Umbrella for all compiler issues labels Apr 19, 2023
@ghost ghost added the untriaged label Apr 19, 2023
@JamesNK
Copy link
Member

JamesNK commented Apr 19, 2023

Please prioritize investigating this. This issue is blocking dotnet/aspnetcore from updating the SDK (it's been blocked on various issues for over 2 weeks)

@jjonescz
Copy link
Member

The issue only appears if the using alias is for a type nested in another component. I'm not sure how that would ever work, but will investigate more. The following test reproduces the issue:

[Fact, WorkItem("https://github.com/dotnet/razor/issues/8610")]
public async Task SourceGenerator_RazorFiles_UsingAlias()
{
    // Arrange
    var project = CreateTestProject(new()
    {
        ["Pages/Index.razor"] = """
            @code {
                public class MyModel { }
            }
            """,
        ["Shared/MyComponent.razor"] = """
            @using MyAlias = Pages.Index.MyModel;

            <MyComponent Data="@Data" />

            @code {
                [Parameter]
                public MyAlias Data { get; set; }
            }
            """,
    });
    var compilation = await project.GetCompilationAsync();
    var driver = await GetDriverAsync(project);

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

    // Assert
    Assert.Empty(result.Diagnostics);
    Assert.Equal(2, result.GeneratedSources.Length);
}

@jjonescz
Copy link
Member

jjonescz commented Apr 19, 2023

OK. This regression has been introduced by #8212. Before, when creating tag helper descriptor for the component, the compilation contained declaration syntax trees of all components, i.e., while inspecting type of property Shared.MyComponent.Data, the nested type Pages.Index+MyModel was available in the compilation and hence resolved properly. After the PR, each component has its descriptor computed in isolation, therefore type of property Shared.MyComponent.Data cannot see the nested type Pages.Index+MyModel.

This leaves the property with an error type which is just emitted as-is. The error has nothing to do with global:: prefixing logic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-compiler Umbrella for all compiler issues bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants