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

Partial Property on class with Primary Constructor shows IDE error CS0229 but compiles fine. #76794

Open
vsfeedback opened this issue Jan 17, 2025 · 2 comments
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice]
I was working on a source generator and ran into a problem. I ended up minimally reproducing with no source generator at all determining it to be an IDE issue. Intellisense/IDE generates a "CS0229 Ambiguity between 'TestClass.Test2' and 'TestClass.Test2'" error when accessing a partial property on a class with a primary constructor, but compilation works with no errors and the code should not be ambiguous.
Problem occurs with the following requirements:

  • Must access the property in a different file than the class is declared. - If the definitions are in the same file as the property access, the issue does not occur
  • The class for the property must have a primary constructor - If using a regular constructor the issue does not occur

I've attached a minimal reproduction project, as well as showing it inline here since it is really small:

using Test;

public class Program
{
    public Program(TestClass test, TestClass2 test2)
    {
        Console.WriteLine(test. Test);
//#error version Compiler version: '4.12.0-3.24572.7 (dfa7fc6b)'. Language version: preview.
        Console.WriteLine(test. Test2); // CS0229 Ambiguity between 'TestClass.Test2' and 'TestClass.Test2'

Console.WriteLine(test2. Test);
        Console.WriteLine(test2. Test2); // No Error
    }

public static void Main() { }
}
namespace Test
{
    public partial class TestClass(string Test)
    {
        public string Test { get; } = Test;
        public partial string Test2 { get; set; } = "";
    }
    public partial class TestClass
    {
        public partial string Test2 { get => field; set => field = value; }
    }
    public partial class TestClass2
    {
        public string Test { get; }
        public partial string Test2 { get; set; } = "";

public TestClass2(string Test) => this. Test = Test;
    }
    public partial class TestClass2
    {
        public partial string Test2 { get => field; set => field = value; }
    }
}

Original Comments

Feedback Bot on 31/12/2024, 08:23 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jan 17, 2025
@deepakrathore33
Copy link
Contributor

This is similar to #76651

@DanFTRX
Copy link

DanFTRX commented Jan 29, 2025

Is this fixed by a87e115 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants