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

Readonly fields have an accessible home when accessed from init-only setter #46323

Merged
merged 4 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3360,19 +3360,18 @@ private static bool HasHome(
}

// while readonly fields have home it is not valid to refer to it when not constructing.
if (!TypeSymbol.Equals(field.ContainingType, method.ContainingType, TypeCompareKind.ConsiderEverything2))
if (!TypeSymbol.Equals(field.ContainingType, method.ContainingType, TypeCompareKind.AllIgnoreOptions))
{
return false;
}


if (field.IsStatic)
{
return method.MethodKind == MethodKind.StaticConstructor;
}
else
{
return method.MethodKind == MethodKind.Constructor &&
return (method.MethodKind == MethodKind.Constructor || method.IsInitOnly) &&
fieldAccess.ReceiverOpt.Kind == BoundKind.ThisReference;
}
}
Expand Down
Loading