Skip to content

Commit

Permalink
Merge branch 'features/readonly-members' into merges/master-to-featur…
Browse files Browse the repository at this point in the history
…es/readonly-members
  • Loading branch information
RikkiGibson committed Apr 1, 2019
2 parents d651e9f + 0d15dd1 commit 5ae1d00
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Invocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ ContainingMemberOrLambda is MethodSymbol containingMethod &&
!method.IsEffectivelyReadOnly &&
!method.IsStatic)
{
Error(diagnostics, ErrorCode.WRN_ImplicitCopyInReadOnlyMember, receiver.Syntax, method.Name, ThisParameterSymbol.SymbolName);
Error(diagnostics, ErrorCode.WRN_ImplicitCopyInReadOnlyMember, receiver.Syntax, method, ThisParameterSymbol.SymbolName);
return false;
}

Expand Down
11 changes: 10 additions & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

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

5 changes: 4 additions & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5419,7 +5419,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>Call to non-readonly member from a 'readonly' member results in an implicit copy.</value>
</data>
<data name="ERR_StaticMemberCantBeReadOnly" xml:space="preserve">
<value>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</value>
<value>Static member '{0}' cannot be marked 'readonly'.</value>
</data>
<data name="ERR_AutoSetterCantBeReadOnly" xml:space="preserve">
<value>Auto-implemented 'set' accessor '{0}' cannot be marked 'readonly'.</value>
Expand All @@ -5439,6 +5439,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_PartialMethodReadOnlyDifference" xml:space="preserve">
<value>Both partial method declarations must be readonly or neither may be readonly</value>
</data>
<data name="ERR_ReadOnlyModMissingAccessor" xml:space="preserve">
<value>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</value>
</data>
<data name="WRN_NullabilityMismatchInArgument" xml:space="preserve">
<value>Argument of type '{0}' cannot be used for parameter '{2}' of type '{1}' in '{3}' due to differences in the nullability of reference types.</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,7 +1690,7 @@ internal enum ErrorCode
ERR_DuplicatePropertyReadOnlyMods = 8661,
ERR_FieldLikeEventCantBeReadOnly = 8662,
ERR_PartialMethodReadOnlyDifference = 8663,

ERR_ReadOnlyModMissingAccessor = 8664,


ERR_RuntimeDoesNotSupportDefaultInterfaceImplementation = 8701,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ protected void CheckModifiersAndType(DiagnosticBag diagnostics)
}
else if (IsReadOnly && IsStatic)
{
// Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.
// Static member '{0}' cannot be marked 'readonly'.
diagnostics.Add(ErrorCode.ERR_StaticMemberCantBeReadOnly, location, this);
}
else if (IsReadOnly && HasAssociatedField)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ private void CheckModifiers(bool hasBody, Location location, DiagnosticBag diagn
}
else if (IsStatic && IsDeclaredReadOnly)
{
// Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.
// Static member '{0}' cannot be marked 'readonly'.
diagnostics.Add(ErrorCode.ERR_StaticMemberCantBeReadOnly, location, this);
}
else if (IsAbstract && !ContainingType.IsAbstract && (ContainingType.TypeKind == TypeKind.Class || ContainingType.TypeKind == TypeKind.Submission))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ private void CheckModifiers(Location location, bool hasBody, bool isAutoProperty
}
else if (LocalDeclaredReadOnly && IsStatic)
{
// Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.
// Static member '{0}' cannot be marked 'readonly'.
diagnostics.Add(ErrorCode.ERR_StaticMemberCantBeReadOnly, location, this);
}
else if (LocalDeclaredReadOnly && _isAutoPropertyAccessor && MethodKind == MethodKind.PropertySet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ private SourcePropertySymbol(
{
diagnostics.Add(ErrorCode.ERR_AccessModMissingAccessor, location, this);
}

// Check that 'readonly' is not set on the one accessor.
if (accessor.LocalDeclaredReadOnly)
{
diagnostics.Add(ErrorCode.ERR_ReadOnlyModMissingAccessor, location, this);
}
}
}
}
Expand Down Expand Up @@ -951,7 +957,7 @@ private void CheckModifiers(Location location, bool isIndexer, DiagnosticBag dia
}
else if (IsStatic && HasReadOnlyModifier)
{
// Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.
// Static member '{0}' cannot be marked 'readonly'.
diagnostics.Add(ErrorCode.ERR_StaticMemberCantBeReadOnly, location, this);
}
else if (IsOverride && (IsNew || IsVirtual))
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">Dílčí vzor vlastnosti vyžaduje odkaz na vlastnost nebo pole k přiřazení, např. „{{ Name: {0} }}“.</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">Přiřazení odkazu {1} k {0} nelze provést, protože {1} má užší řídicí obor než {0}.</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">Ein Eigenschaftsteilmuster erfordert einen Verweis auf die abzugleichende Eigenschaft oder das abzugleichende Feld. Beispiel: "{{ Name: {0} }}"</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">ref-assign von "{1}" zu "{0}" ist nicht möglich, weil "{1}" einen geringeren Escapebereich als "{0}" aufweist.</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">El subpatrón de una propiedad requiere una referencia a la propiedad o al campo que debe coincidir; por ejemplo, "{{ Name: {0} }}"</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">No se puede asignar referencia "{1}" a "{0}" porque "{1}" tiene un ámbito de escape más limitado que "{0}".</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">Un sous-modèle de propriété nécessite une correspondance de la référence à la propriété ou au champ. Exemple : '{{ Nom: {0} }}'</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">Impossible d'effectuer une assignation par référence de '{1}' vers '{0}', car '{1}' a une portée de sortie plus limitée que '{0}'.</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">Con un criterio secondario di proprietà è richiesto un riferimento alla proprietà o al campo da abbinare, ad esempio '{{ Name: {0} }}'</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">Non è possibile assegnare '{1}' a '{0}' come ref perché l'ambito di escape di '{1}' è ridotto rispetto a quello di '{0}'.</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">プロパティ サブパターンには、一致させるプロパティまたはフィールドへの参照が必要です。例: '{{ Name: {0} }}'</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">'{1}' を '{0}' に ref 割り当てすることはできません。'{1}' のエスケープ スコープが '{0}' より狭いためです。</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">속성 하위 패턴은 일치시킬 속성 또는 필드에 대한 참조가 필요합니다(예: '{{ Name: {0} }}')</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">'{1}'을(를) '{0}'에 참조 할당할 수 없습니다. '{1}'이(가) '{0}'보다 이스케이프 범위가 좁기 때문입니다.</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
9 changes: 7 additions & 2 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@
<target state="translated">Wzorzec podrzędny właściwości wymaga odwołania do właściwości lub pola, które należy dopasować, na przykład „{{ Name: {0} }}”</target>
<note />
</trans-unit>
<trans-unit id="ERR_ReadOnlyModMissingAccessor">
<source>'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</source>
<target state="new">'{0}': 'readonly' can only be used on accessors if the property or indexer has both a get and a set accessor</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefAssignNarrower">
<source>Cannot ref-assign '{1}' to '{0}' because '{1}' has a narrower escape scope than '{0}'.</source>
<target state="translated">Nie można przypisać odwołania elementu „{1}” do elementu „{0}”, ponieważ element „{1}” ma węższy zakres wyjścia niż element „{0}”.</target>
Expand Down Expand Up @@ -343,8 +348,8 @@
<note />
</trans-unit>
<trans-unit id="ERR_StaticMemberCantBeReadOnly">
<source>Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly' because readonly members cannot modify 'this' and static members do not have a 'this' parameter.</target>
<source>Static member '{0}' cannot be marked 'readonly'.</source>
<target state="new">Static member '{0}' cannot be marked 'readonly'.</target>
<note />
</trans-unit>
<trans-unit id="ERR_SwitchArmSubsumed">
Expand Down
Loading

0 comments on commit 5ae1d00

Please sign in to comment.