Skip to content
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
6 changes: 6 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -7784,4 +7784,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="WRN_TargetDifferentRefness_Title" xml:space="preserve">
<value>Reference kind modifier of parameter doesn't match the corresponding parameter in target.</value>
</data>
<data name="WRN_UseDefViolationRefField" xml:space="preserve">
<value>Ref field '{0}' should be ref-assigned before use.</value>
</data>
<data name="WRN_UseDefViolationRefField_Title" xml:space="preserve">
<value>Ref field should be ref-assigned before use.</value>
</data>
</root>
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,7 @@ internal enum ErrorCode
WRN_TargetDifferentRefness = 9198,
ERR_OutAttrOnRefReadonlyParam = 9199,
WRN_RefReadonlyParameterDefaultValue = 9200,
WRN_UseDefViolationRefField = 9201,

#endregion

Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ internal static int GetWarningLevel(ErrorCode code)
case ErrorCode.WRN_HidingDifferentRefness:
case ErrorCode.WRN_TargetDifferentRefness:
case ErrorCode.WRN_RefReadonlyParameterDefaultValue:
case ErrorCode.WRN_UseDefViolationRefField:
return 1;
default:
return 0;
Expand Down Expand Up @@ -2396,6 +2397,7 @@ internal static bool IsBuildOnlyDiagnostic(ErrorCode code)
case ErrorCode.ERR_OutAttrOnRefReadonlyParam:
case ErrorCode.WRN_RefReadonlyParameterDefaultValue:
case ErrorCode.WRN_ByValArraySizeConstRequired:
case ErrorCode.WRN_UseDefViolationRefField:
return false;
default:
// NOTE: All error codes must be explicitly handled in this switch statement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,18 @@ void addDiagnosticForStructField(int fieldSlot, FieldSymbol fieldSymbol)
// should we handle nested fields here? https://github.com/dotnet/roslyn/issues/59890
AddImplicitlyInitializedField((FieldSymbol)fieldIdentifier.Symbol);

if (compilation.IsFeatureEnabled(MessageID.IDS_FeatureAutoDefaultStructs))
if (fieldSymbol.RefKind != RefKind.None)
{
// 'hasAssociatedProperty' is only true here in error scenarios where we don't need to report this as a cascading diagnostic
if (!hasAssociatedProperty)
{
Diagnostics.Add(
ErrorCode.WRN_UseDefViolationRefField,
node.Location,
symbolName);
}
}
else if (compilation.IsFeatureEnabled(MessageID.IDS_FeatureAutoDefaultStructs))
{
Diagnostics.Add(
hasAssociatedProperty ? ErrorCode.WRN_UseDefViolationPropertySupportedVersion : ErrorCode.WRN_UseDefViolationFieldSupportedVersion,
Expand Down Expand Up @@ -1497,6 +1508,10 @@ private Symbol UseNonFieldSymbolUnsafely(BoundExpression expression)

protected void Assign(BoundNode node, BoundExpression value, bool isRef = false, bool read = true)
{
if (!isRef && node is BoundFieldAccess { FieldSymbol.RefKind: not RefKind.None } fieldAccess)
{
CheckAssigned(fieldAccess, node.Syntax);
}
AssignImpl(node, value, written: true, isRef: isRef, read: read);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading