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

Don't re-initialize static fields in Console #35409

Merged
merged 1 commit into from
Apr 24, 2020

Conversation

marek-safar
Copy link
Contributor

the compiler is not capable removing the initialization

the compiler is not capable removing the initialization
@ghost
Copy link

ghost commented Apr 24, 2020

Tagging subscribers to this area: @eiriktsarpalis
Notify danmosemsft if you want to be subscribed.

@stephentoub
Copy link
Member

stephentoub commented Apr 24, 2020

the compiler is not capable removing the initialization

It's fine to remove the = false, but the C# compiler does remove those assignments. It will still generate an empty cctor, though, if those would have been the only initialization; that's tracked by dotnet/roslyn#42985. In this case, at least one other field is initialized, so the static cctor is still required.

@marek-safar
Copy link
Contributor Author

but the C# compiler does remove those assignments

It does not in all cases like this one. It does remove the assignments only where there is no needed assignment. Simple example bellow

class C
{
    static object o = new object ();
    static bool b = false;
}

@stephentoub
Copy link
Member

It does not in all cases like this one.

If that's true that's a bug. Have you opened one on dotnet/roslyn?

@EgorBo
Copy link
Member

EgorBo commented Apr 24, 2020

I see there are more cases like this in BCL (I used static (.*) = null; and static (.*) = false; regex in VSCode)

@marek-safar
Copy link
Contributor Author

marek-safar commented Apr 24, 2020

Have you opened one on dotnet/roslyn?

Tracking at dotnet/roslyn#43652 but I don't agree this is a bug.

@stephentoub stephentoub merged commit ed1b8aa into dotnet:master Apr 24, 2020
@marek-safar
Copy link
Contributor Author

I see there are more cases like this in BCL (I used static (.) = null; and static (.) = false; regex in VSCode)

@EgorBo could you submit PR to clear them up?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants