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
1 change: 1 addition & 0 deletions docs/compilers/CSharp/Warnversion Warning Waves.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ The table below describes all of the warnings controlled by warning levels `5` o

| Warning ID | warning level | Description |
|------------|---------|-------------|
| CS7023 | 5 | [A static type is used in an 'is' or 'as' expression](https://github.com/dotnet/roslyn/issues/30198) |
| CS8073 | 5 | [Expression always true (or false) when comparing a struct to null](https://github.com/dotnet/roslyn/issues/45744) |
18 changes: 8 additions & 10 deletions src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2875,12 +2875,11 @@ private bool IsOperatorErrors(CSharpSyntaxNode node, TypeSymbol operandType, Bou
// The native compiler allows "x is C" where C is a static class. This
// is strictly illegal according to the specification (see the section
// called "Referencing Static Class Types".) To retain compatibility we
// allow it, but when /feature:strict is enabled we break with the native
// compiler and turn this into an error, as it should be.
if (targetType.IsStatic && Compilation.FeatureStrictEnabled)
// allow it, but when /warn:5 or higher we break with the native
// compiler and turn this into a warning.
if (targetType.IsStatic)
{
Error(diagnostics, ErrorCode.ERR_StaticInAsOrIs, node, targetType);
return true;
Error(diagnostics, ErrorCode.WRN_StaticInAsOrIs, node, targetType);
}

if ((object)operandType != null && operandType.IsPointerOrFunctionPointer() || targetType.IsPointerOrFunctionPointer())
Expand Down Expand Up @@ -3401,12 +3400,11 @@ private BoundExpression BindAsOperator(BinaryExpressionSyntax node, DiagnosticBa
// a static type C to be an expression of type C.
// It also allows "someObject as C" if "someObject"
// is of type object. To retain compatibility we
// allow it, but when /feature:strict is enabled we break with the native
// compiler and turn this into an error, as it should be.
if (targetType.IsStatic && Compilation.FeatureStrictEnabled)
// allow it, but when /warn:5 or higher we break with the native
// compiler and turn this into a warning.
if (targetType.IsStatic)
{
Error(diagnostics, ErrorCode.ERR_StaticInAsOrIs, node, targetType);
return new BoundAsOperator(node, operand, typeExpression, Conversion.NoConversion, resultType, hasErrors: true);
Error(diagnostics, ErrorCode.WRN_StaticInAsOrIs, node, targetType);
}

if (operand.IsLiteralNull())
Expand Down
5 changes: 4 additions & 1 deletion src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3896,9 +3896,12 @@ You should consider suppressing the warning only if you're sure that you don't w
<data name="WRN_MainIgnored_Title" xml:space="preserve">
<value>The entry point of the program is global code; ignoring entry point</value>
</data>
<data name="ERR_StaticInAsOrIs" xml:space="preserve">
<data name="WRN_StaticInAsOrIs" xml:space="preserve">
<value>The second operand of an 'is' or 'as' operator may not be static type '{0}'</value>
</data>
<data name="WRN_StaticInAsOrIs_Title" xml:space="preserve">
<value>The second operand of an 'is' or 'as' operator may not be a static type</value>
</data>
<data name="ERR_BadVisEventType" xml:space="preserve">
<value>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</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 @@ -1166,7 +1166,7 @@ internal enum ErrorCode
ERR_YieldNotAllowedInScript = 7020,
ERR_NamespaceNotAllowedInScript = 7021,
WRN_MainIgnored = 7022,
ERR_StaticInAsOrIs = 7023,
WRN_StaticInAsOrIs = 7023,
ERR_InvalidDelegateType = 7024,
ERR_BadVisEventType = 7025,
ERR_GlobalAttributesNotAllowed = 7026,
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ internal static int GetWarningLevel(ErrorCode code)
switch (code)
{
case ErrorCode.WRN_NubExprIsConstBool2:
case ErrorCode.WRN_StaticInAsOrIs:
// Warning level 5 is exclusively for warnings introduced in the compiler
// shipped with dotnet 5 (C# 9) and that can be reported for pre-existing code.
return 5;
Expand Down

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

15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,16 @@
<target state="translated">Metoda označená jako [DoesNotReturn] by neměla vracet hodnotu</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be static type '{0}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs_Title">
<source>The second operand of an 'is' or 'as' operator may not be a static type</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be a static type</target>
<note />
</trans-unit>
<trans-unit id="WRN_SwitchExpressionNotExhaustive">
<source>The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</source>
<target state="new">The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</target>
Expand Down Expand Up @@ -8272,11 +8282,6 @@ Potlačení upozornění zvažte jenom v případě, když určitě nechcete če
<target state="needs-review-translation">Vstupním bodem programu je globální kód skriptu. Vstupní bod se ignoruje.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="translated">Druhý operand operátoru is nebo as nesmí být statického typu {0}.</target>
<note />
</trans-unit>
<trans-unit id="ERR_BadVisEventType">
<source>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</source>
<target state="translated">Nekonzistentní dostupnost: Typ události {1} je míň dostupný než událost {0}.</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,16 @@
<target state="translated">Eine mit [DoesNotReturn] gekennzeichnete Methode darf nicht zurückgegeben werden.</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be static type '{0}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs_Title">
<source>The second operand of an 'is' or 'as' operator may not be a static type</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be a static type</target>
<note />
</trans-unit>
<trans-unit id="WRN_SwitchExpressionNotExhaustive">
<source>The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</source>
<target state="new">The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</target>
Expand Down Expand Up @@ -8272,11 +8282,6 @@ Sie sollten das Unterdrücken der Warnung nur in Betracht ziehen, wenn Sie siche
<target state="needs-review-translation">Der Einstiegspunkt des Programms ist globaler Skriptcode; der Einstiegspunkt wird ignoriert.</target>
<note />
</trans-unit>
<trans-unit id="ERR_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="translated">Der zweite Operand eines is- oder as-Operators darf nicht den statischen Typ "{0}" aufweisen.</target>
<note />
</trans-unit>
<trans-unit id="ERR_BadVisEventType">
<source>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</source>
<target state="translated">Inkonsistenter Zugriff: Ereignistyp "{1}" ist weniger zugreifbar als Ereignis "{0}".</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,16 @@
<target state="translated">Un método marcado [DoesNotReturn] no debe devolver.</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be static type '{0}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs_Title">
<source>The second operand of an 'is' or 'as' operator may not be a static type</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be a static type</target>
<note />
</trans-unit>
<trans-unit id="WRN_SwitchExpressionNotExhaustive">
<source>The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</source>
<target state="new">The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</target>
Expand Down Expand Up @@ -8272,11 +8282,6 @@ Considere la posibilidad de suprimir la advertencia solo si tiene la seguridad d
<target state="needs-review-translation">El punto de entrada del programa es código de script global. Ignorando punto de entrada</target>
<note />
</trans-unit>
<trans-unit id="ERR_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="translated">El segundo operando de un operador 'is' o 'as' no puede ser el tipo estático '{0}'</target>
<note />
</trans-unit>
<trans-unit id="ERR_BadVisEventType">
<source>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</source>
<target state="translated">Incoherencia de accesibilidad: el tipo de evento '{1}' es menos accesible que el evento '{0}'</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,16 @@
<target state="translated">Une méthode marquée [DoesNotReturn] ne doit pas être retournée.</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be static type '{0}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs_Title">
<source>The second operand of an 'is' or 'as' operator may not be a static type</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be a static type</target>
<note />
</trans-unit>
<trans-unit id="WRN_SwitchExpressionNotExhaustive">
<source>The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</source>
<target state="new">The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</target>
Expand Down Expand Up @@ -8272,11 +8282,6 @@ Supprimez l'avertissement seulement si vous êtes sûr de ne pas vouloir attendr
<target state="needs-review-translation">Le point d'entrée du programme est du code de script global ; ce point d'entrée est ignoré</target>
<note />
</trans-unit>
<trans-unit id="ERR_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="translated">Le second opérande d'un opérateur 'is' ou 'as' ne peut pas être du type static '{0}'</target>
<note />
</trans-unit>
<trans-unit id="ERR_BadVisEventType">
<source>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</source>
<target state="translated">Accessibilité incohérente : le type d'événement '{1}' est moins accessible que l'événement '{0}'</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,16 @@
<target state="translated">Un metodo contrassegnato con [DoesNotReturn] non deve essere restituito.</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be static type '{0}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs_Title">
<source>The second operand of an 'is' or 'as' operator may not be a static type</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be a static type</target>
<note />
</trans-unit>
<trans-unit id="WRN_SwitchExpressionNotExhaustive">
<source>The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</source>
<target state="new">The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</target>
Expand Down Expand Up @@ -8272,11 +8282,6 @@ Come procedura consigliata, è consigliabile attendere sempre la chiamata.
<target state="needs-review-translation">Il punto di ingresso del programma è codice script globale. Il punto di ingresso verrà ignorato</target>
<note />
</trans-unit>
<trans-unit id="ERR_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="translated">Il secondo operando di un operatore 'is' o 'as' non può essere di tipo statico '{0}'</target>
<note />
</trans-unit>
<trans-unit id="ERR_BadVisEventType">
<source>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</source>
<target state="translated">Accessibilità incoerente: il tipo di evento '{1}' è meno accessibile di '{0}'</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,16 @@
<target state="translated">[DoesNotReturn] とマークされたメソッドの返却禁止。</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be static type '{0}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs_Title">
<source>The second operand of an 'is' or 'as' operator may not be a static type</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be a static type</target>
<note />
</trans-unit>
<trans-unit id="WRN_SwitchExpressionNotExhaustive">
<source>The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</source>
<target state="new">The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</target>
Expand Down Expand Up @@ -8272,11 +8282,6 @@ You should consider suppressing the warning only if you're sure that you don't w
<target state="needs-review-translation">プログラムのエントリ ポイントは、グローバル スクリプト コードです。エントリ ポイントを無視します</target>
<note />
</trans-unit>
<trans-unit id="ERR_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="translated">is' または 'as' 演算子の 2 番目のオペランドはスタティック型 '{0}' にすることはできません。</target>
<note />
</trans-unit>
<trans-unit id="ERR_BadVisEventType">
<source>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</source>
<target state="translated">アクセシビリティに一貫性がありません。イベント型 '{1}' のアクセシビリティはイベント '{0}' よりも低く設定されています。</target>
Expand Down
15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,16 @@
<target state="translated">[DoesNotReturn]으로 표시된 메서드는 반환하지 않아야 합니다.</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be static type '{0}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_StaticInAsOrIs_Title">
<source>The second operand of an 'is' or 'as' operator may not be a static type</source>
<target state="new">The second operand of an 'is' or 'as' operator may not be a static type</target>
<note />
</trans-unit>
<trans-unit id="WRN_SwitchExpressionNotExhaustive">
<source>The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</source>
<target state="new">The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{0}' is not covered.</target>
Expand Down Expand Up @@ -8272,11 +8282,6 @@ You should consider suppressing the warning only if you're sure that you don't w
<target state="needs-review-translation">프로그램의 진입점이 전역 스크립트 코드이며 진입점을 무시함</target>
<note />
</trans-unit>
<trans-unit id="ERR_StaticInAsOrIs">
<source>The second operand of an 'is' or 'as' operator may not be static type '{0}'</source>
<target state="translated">is' 또는 'as' 연산자의 두 번째 피연산자는 '{0}' 정적 형식일 수 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="ERR_BadVisEventType">
<source>Inconsistent accessibility: event type '{1}' is less accessible than event '{0}'</source>
<target state="translated">일관성 없는 액세스 가능성: '{1}' 이벤트 형식이 '{0}' 이벤트보다 액세스하기 어렵습니다.</target>
Expand Down
Loading