diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index fe08446c65fff..c7d6334a1bdc3 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -318,6 +318,18 @@ type parameter + + array + + + pointer + + + function pointer + + + dynamic + using alias @@ -7595,4 +7607,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ An interceptor cannot be marked with 'UnmanagedCallersOnlyAttribute'. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 3de89983bc479..29b608b26a13c 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -2218,6 +2218,8 @@ internal enum ErrorCode ERR_InterceptorCannotInterceptNameof = 9160, ERR_InterceptorCannotUseUnmanagedCallersOnly = 9161, + ERR_BadUsingStaticType = 9162, + #endregion // Note: you will need to do the following after adding warnings: diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index ba64451c05346..35296d88091ee 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -2341,6 +2341,7 @@ internal static bool IsBuildOnlyDiagnostic(ErrorCode code) case ErrorCode.ERR_ConstantValueOfTypeExpected: case ErrorCode.ERR_UnsupportedPrimaryConstructorParameterCapturingRefAny: case ErrorCode.ERR_InterceptorCannotUseUnmanagedCallersOnly: + case ErrorCode.ERR_BadUsingStaticType: return false; default: // NOTE: All error codes must be explicitly handled in this switch statement diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index 92e08d6ae0c10..4e8ccdfa7c1e3 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -82,6 +82,11 @@ internal enum MessageID IDS_FeatureAutoPropertyInitializer = MessageBase + 12649, IDS_SK_TYPE_OR_NAMESPACE = MessageBase + 12652, + IDS_SK_ARRAY = MessageBase + 12653, + IDS_SK_POINTER = MessageBase + 12654, + IDS_SK_FUNCTION_POINTER = MessageBase + 12655, + IDS_SK_DYNAMIC = MessageBase + 12656, + IDS_Contravariant = MessageBase + 12659, IDS_Contravariantly = MessageBase + 12660, IDS_Covariant = MessageBase + 12661, diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.AliasesAndUsings.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.AliasesAndUsings.cs index bdc398d4ddf93..da43dd8d6e7f3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.AliasesAndUsings.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamespaceSymbol.AliasesAndUsings.cs @@ -764,6 +764,7 @@ UsingsAndDiagnostics buildUsings( declarationBinder ??= compilation.GetBinderFactory(declarationSyntax.SyntaxTree).GetBinder(usingDirective.NamespaceOrType).WithAdditionalFlags(flags); var imported = declarationBinder.BindNamespaceOrTypeSymbol(usingDirective.NamespaceOrType, directiveDiagnostics, basesBeingResolved).NamespaceOrTypeSymbol; + bool addDirectiveDiagnostics = true; if (imported.Kind == SymbolKind.Namespace) { @@ -814,6 +815,15 @@ UsingsAndDiagnostics buildUsings( } } } + else if (imported.Kind is SymbolKind.ArrayType or SymbolKind.PointerType or SymbolKind.FunctionPointerType or SymbolKind.DynamicType) + { + diagnostics.Add(ErrorCode.ERR_BadUsingStaticType, usingDirective.NamespaceOrType.Location, imported.GetKindText()); + + // Don't bother adding sub diagnostics (like that an unsafe type was referenced). The + // primary thing we want to report is simply that the using-static points to something + // entirely invalid. + addDirectiveDiagnostics = false; + } else if (imported.Kind != SymbolKind.ErrorType) { // Do not report additional error if the symbol itself is erroneous. @@ -825,7 +835,11 @@ UsingsAndDiagnostics buildUsings( MessageID.IDS_SK_TYPE_OR_NAMESPACE.Localize()); } - diagnostics.AddRange(directiveDiagnostics.DiagnosticBag); + if (addDirectiveDiagnostics) + { + diagnostics.AddRange(directiveDiagnostics.DiagnosticBag); + } + directiveDiagnostics.Free(); } } diff --git a/src/Compilers/CSharp/Portable/Symbols/SymbolKindExtensions.cs b/src/Compilers/CSharp/Portable/Symbols/SymbolKindExtensions.cs index 2ea94f086818b..4d1b8cca17800 100644 --- a/src/Compilers/CSharp/Portable/Symbols/SymbolKindExtensions.cs +++ b/src/Compilers/CSharp/Portable/Symbols/SymbolKindExtensions.cs @@ -23,6 +23,14 @@ public static LocalizableErrorArgument Localize(this SymbolKind kind) return MessageID.IDS_SK_TYPE.Localize(); case SymbolKind.TypeParameter: return MessageID.IDS_SK_TYVAR.Localize(); + case SymbolKind.ArrayType: + return MessageID.IDS_SK_ARRAY.Localize(); + case SymbolKind.PointerType: + return MessageID.IDS_SK_POINTER.Localize(); + case SymbolKind.FunctionPointerType: + return MessageID.IDS_SK_FUNCTION_POINTER.Localize(); + case SymbolKind.DynamicType: + return MessageID.IDS_SK_DYNAMIC.Localize(); case SymbolKind.Method: return MessageID.IDS_SK_METHOD.Localize(); case SymbolKind.Property: diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 8b0b5bb1dee8e..71efa98e621f7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -287,6 +287,11 @@ Pouze „using static“ nebo „using alias“ může být „nebezpečný“. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. Atribut AsyncMethodBuilder je u anonymních metod bez explicitního návratového typu zakázaný. @@ -2147,6 +2152,26 @@ přístup k elementu ukazatele + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. Operátor „&“ by se neměl používat u parametrů nebo místních proměnných v asynchronních metodách. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index b26d8dbc0662c..9b3bcec4c17ca 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -287,6 +287,11 @@ Nur ein "using static" oder "using alias" kann "unsicher" sein. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. Das AsyncMethodBuilder-Attribut ist für anonyme Methoden ohne expliziten Rückgabetyp unzulässig. @@ -2147,6 +2152,26 @@ Zeigerelementzugriff + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. Der Operator '&' sollte nicht für Parameter oder lokale Variablen in asynchronen Methoden verwendet werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index e23aff2338aa8..0b7efd6c388a9 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -287,6 +287,11 @@ Solo un ''usando estática'' o ''usando alias'' puede ser ''No seguro''. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. El atributo AsyncMethodBuilder no se permite en métodos anónimos sin un tipo de valor devuelto explícito. @@ -2147,6 +2152,26 @@ acceso al elemento de puntero + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. El operador ''&'' no debe usarse en parámetros o variables locales en métodos asincrónicos. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 89309afed07ee..700cd0639ce9b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -287,6 +287,11 @@ Seul un 'using static' ou 'using alias' peut être 'unsafe'. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. L'attribut AsyncMethodBuilder n'est pas autorisé pour les méthodes anonymes sans type de retour explicite. @@ -2147,6 +2152,26 @@ accès à l’élément de pointeur + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. L’opérateur '&' ne doit pas être utilisé sur les paramètres ou les variables locales dans les méthodes asynchrones. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 7df2a05be844e..565305a5a6f5a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -287,6 +287,11 @@ Solo 'using static' o 'using alias' può essere 'unsafe'. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. L'attributo AsyncMethodBuilder non è consentito in metodi anonimi senza un tipo restituito esplicito. @@ -2147,6 +2152,26 @@ accesso all'elemento puntatore + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. L'operatore '&' non deve essere usato su parametri o variabili locali in metodi asincroni. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 3da351645e6d8..75c7fca29d388 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -287,6 +287,11 @@ 'unsafe' に設定できるのは、'using static' または 'using エイリアス' のみです。 + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. AsyncMethodBuilder 属性は、明示的な戻り値の型のない匿名メソッドでは許可されていません。 @@ -2147,6 +2152,26 @@ ポインター要素アクセス + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. '&' 演算子は、非同期メソッドのパラメーターまたはローカル変数では使用できません。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 83c32f936af69..d0680f8c21b55 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -287,6 +287,11 @@ 'using static' 또는 'using alias'만 'unsafe'일 수 있습니다. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. AsyncMethodBuilder 특성은 명시적 반환 형식이 없는 익명 메서드에서 허용되지 않습니다. @@ -2147,6 +2152,26 @@ 포인터 요소 액세스 + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. '&' 연산자는 비동기 메서드의 매개 변수 또는 지역 변수에 사용하면 안 됩니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 5f75569d9cb2b..f3b3b5c430049 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -287,6 +287,11 @@ Tylko element „użycie statyczne” lub „użycie aliasu” może być „niebezpieczne”. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. Atrybut AsyncMethodBuilder jest niedozwolony w metodach anonimowych bez jawnego zwracanego typu. @@ -2147,6 +2152,26 @@ dostęp do elementu wskaźnika + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. Operator „&” nie powinien być używany w parametrach ani zmiennych lokalnych w metodach asynchronicznych. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 21d2b3f76bb84..bfb267170c029 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -287,6 +287,11 @@ Somente um 'usando estático' ou 'usando alias' pode ser 'inseguro'. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. O atributo AsyncMethodBuilder não é permitido em métodos anônimos sem um tipo de retorno explícito. @@ -2147,6 +2152,26 @@ acesso ao elemento de ponteiro + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. O operador '&' não deve ser usado em parâmetros ou variáveis locais em métodos assíncronos. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 84cf2e7a27e04..6b3f159d417eb 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -287,6 +287,11 @@ Только параметр "using static" или "using alias" может иметь значение "unsafe". + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. Атрибут AsyncMethodBuilder запрещен для анонимных методов без явного типа возвращаемого значения. @@ -2147,6 +2152,26 @@ доступ к элементу указателя + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. Оператор "&" не следует использовать для параметров или локальных переменных в асинхронных методах. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 3796682548435..6d81a21ab7397 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -287,6 +287,11 @@ Yalnızca 'using static' veya 'using alias' 'unsafe' olabilir. + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. Açık dönüş türü olmadan, anonim yöntemlerde AsyncMethodBuilder özniteliğine izin verilmez. @@ -2147,6 +2152,26 @@ işaretçi öğesi erişimi + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. '&' işleci, zaman uyumsuz yöntemlerdeki parametrelerde veya yerel değişkenlerde kullanılmamalı. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 46926dda245a6..176bb68d626ca 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -287,6 +287,11 @@ 只有 “using static” 或 “using alias” 才能为 “unsafe”。 + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. 没有显式返回类型的匿名方法不允许使用 AsyncMethodBuilder 属性。 @@ -2147,6 +2152,26 @@ 指针元素访问 + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. '&' 运算符不应用于异步方法中的参数或局部变量。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index b162afdf91e91..b7050e9480662 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -287,6 +287,11 @@ 只有 'using static' 或 'using alias' 可以是 'unsafe'。 + + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + '{0}' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate, or namespace can be used. + + The AsyncMethodBuilder attribute is disallowed on anonymous methods without an explicit return type. 沒有明確傳回型別的匿名方法上不允許 AsyncMethodBuilder 屬性。 @@ -2147,6 +2152,26 @@ 指標元素存取 + + array + array + + + + dynamic + dynamic + + + + function pointer + function pointer + + + + pointer + pointer + + The '&' operator should not be used on parameters or local variables in async methods. '&' 運算子不應該用於非同步方法中的參數或區域變數。 diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/UsingAliasTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/UsingAliasTests.cs index d1b4321085c30..a1970eaf42c09 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/UsingAliasTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/UsingAliasTests.cs @@ -4,6 +4,7 @@ #nullable disable +using System; using System.Linq; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; @@ -969,5 +970,98 @@ void M() } """).VerifyDiagnostics(); } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68546")] + public void AliasToArrayReferencedInUsingStatic() + { + CreateCompilation(""" + using A = int[]; + + namespace N + { + using static A; + } + """).VerifyDiagnostics( + // (5,5): hidden CS8019: Unnecessary using directive. + // using static A; + Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using static A;").WithLocation(5, 5), + // (5,18): error CS9137: 'array' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used. + // using static A; + Diagnostic(ErrorCode.ERR_BadUsingStaticType, "A").WithArguments("array").WithLocation(5, 18)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68546")] + public void AliasToPointerReferencedInUsingStatic() + { + CreateCompilation(""" + using unsafe A = int*; + + namespace N + { + using static A; + } + """, options: TestOptions.UnsafeDebugDll).VerifyDiagnostics( + // (5,5): hidden CS8019: Unnecessary using directive. + // using static A; + Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using static A;").WithLocation(5, 5), + // (5,18): error CS9137: 'pointer' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used. + // using static A; + Diagnostic(ErrorCode.ERR_BadUsingStaticType, "A").WithArguments("pointer").WithLocation(5, 18)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68546")] + public void AliasToFunctionPointerReferencedInUsingStatic() + { + CreateCompilation(""" + using unsafe A = delegate*; + + namespace N + { + using static A; + } + """, options: TestOptions.UnsafeDebugDll).VerifyDiagnostics( + // (5,5): hidden CS8019: Unnecessary using directive. + // using static A; + Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using static A;").WithLocation(5, 5), + // (5,18): error CS9137: 'function pointer' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used. + // using static A; + Diagnostic(ErrorCode.ERR_BadUsingStaticType, "A").WithArguments("function pointer").WithLocation(5, 18)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68546")] + public void AliasToDynamicReferencedInUsingStatic() + { + CreateCompilation(""" + using A = dynamic; + + namespace N + { + using static A; + } + """).VerifyDiagnostics( + // (5,5): hidden CS8019: Unnecessary using directive. + // using static A; + Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using static A;").WithLocation(5, 5), + // (5,18): error CS9137: 'dynamic' type is not valid for 'using static'. Only a class, struct, interface, enum, delegate or namespace can be used. + // using static A; + Diagnostic(ErrorCode.ERR_BadUsingStaticType, "A").WithArguments("dynamic").WithLocation(5, 18)); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68546")] + public void AliasToTupleReferencedInUsingStatic() + { + // Allowed, as it's the same as `using A = System.ValueTuple;` + CreateCompilation(""" + using A = (int, int); + + namespace N + { + using static A; + } + """).VerifyDiagnostics( + // (5,5): hidden CS8019: Unnecessary using directive. + // using static A; + Diagnostic(ErrorCode.HDN_UnusedUsingDirective, "using static A;").WithLocation(5, 5)); + } } }