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

Config binder generator generates uncompilable code when a private nested type is used #90909

Closed
stephentoub opened this issue Aug 22, 2023 · 4 comments · Fixed by #91657
Closed
Assignees
Labels
area-Extensions-Configuration blocking-release bug source-generator Indicates an issue with a source generator feature
Milestone

Comments

@stephentoub
Copy link
Member

This compiles fine:

using Microsoft.Extensions.Configuration;

internal class Program
{
    private static void Main() { }

    private static C Foo(IConfiguration configuration)
    {
        C c = new();
        configuration.Bind(c);
        return c;
    }

    internal sealed class C
    {
        public int Value { get; set; }
    }
}

but changing:

internal sealed class C

to

private sealed class C

produces an error about C being inaccessible, as the generator emits code into another class that tries to access that property.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Aug 22, 2023
@ghost
Copy link

ghost commented Aug 22, 2023

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

This compiles fine:

using Microsoft.Extensions.Configuration;

internal class Program
{
    private static void Main() { }

    private static C Foo(IConfiguration configuration)
    {
        C c = new();
        configuration.Bind(c);
        return c;
    }

    internal sealed class C
    {
        public int Value { get; set; }
    }
}

but changing:

internal sealed class C

to

private sealed class C

produces an error about C being inaccessible, as the generator emits code into another class that tries to access that property.

Author: stephentoub
Assignees: -
Labels:

area-Extensions-Configuration

Milestone: -

@tarekgh tarekgh added this to the 8.0.0 milestone Aug 22, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Aug 22, 2023
@tarekgh tarekgh added the source-generator Indicates an issue with a source generator feature label Aug 22, 2023
@layomia
Copy link
Contributor

layomia commented Aug 23, 2023

I'd say the resolution would be to emit a diagnostic & omit code to support inaccessible members.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 6, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 7, 2023
@layomia
Copy link
Contributor

layomia commented Sep 7, 2023

Needs RC-2 port of #91657.

@layomia layomia reopened this Sep 7, 2023
@layomia
Copy link
Contributor

layomia commented Sep 15, 2023

Fixed for RC 2 - #91967.

@layomia layomia closed this as completed Sep 15, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Configuration blocking-release bug source-generator Indicates an issue with a source generator feature
Projects
None yet
3 participants