This is a migrated thread and some comments may be shown as answers.

Field 'xyz' is never assigned -> structs

1 Answer 26 Views
Code Analysis
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wolfgang
Top achievements
Rank 1
Wolfgang asked on 19 Jul 2013, 09:11 AM
Hi,
i have the follwoing interesting issue:
if i use a struct, i get a warningthat the field is never assigned.

Example:

public struct Test
{
    public int Prop1 { get; set; }
}
  
class Program
{
    private static Test test1; // Justcode warning: Field 'xyz' is never assigned
     
    static void Main(string[] args)
    {
        test1.Prop1 = 1;
    }
}

if i change "private static Test test1;" to "public static Test test1;"the warning goes away.

Why do I get the warning? The struct has no ctor. I could put a new call in the file so that the warning goes away "test1 = new Test();" .

But why should it be needed? And why shouldn't it be needed if the field is public instead of private?

Best regards,
Wolfgang

1 Answer, 1 is accepted

Sort by
0
Zdravko
Telerik team
answered on 23 Jul 2013, 11:42 AM
Hello Wolfgang,

 Thanks for reporting.
Indeed this is a bug and we have plans to remove the warning for struct types. It is already logged in our product backlog and a fix awaits.
Thank you.

Regards,
Zdravko
Telerik
Share what you think about JustCode with us, so we can help you even better! You can use the built-in feedback tool inside JustCode, our forum, or our JustCode feedback portal.
Tags
Code Analysis
Asked by
Wolfgang
Top achievements
Rank 1
Answers by
Zdravko
Telerik team
Share this question
or