diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 197d08bdbf6f5..be221bed765f8 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -699,6 +699,9 @@ A namespace cannot directly contain members such as fields, methods or statements + + A compilation unit cannot directly contain members such as fields, methods or properties + '{0}' does not contain a definition for '{1}' diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index abd5751538273..5153ca9d395e1 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -2446,6 +2446,7 @@ internal enum ErrorCode ERR_InequalityOperatorInPatternNotSupported = 9345, ERR_EncUpdateRequiresEmittingExplicitInterfaceImplementationNotSupportedByTheRuntime = 9346, ERR_ExtensionParameterInStaticContext = 9347, + ERR_CompilationUnitUnexpected = 9348, // Note: you will need to do the following after adding errors: // 1) Update ErrorFacts.IsBuildOnlyDiagnostic (src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index 893ba4230d9de..a99746c3a5f12 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -2554,6 +2554,7 @@ or ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList or ErrorCode.ERR_EqualityOperatorInPatternNotSupported or ErrorCode.ERR_InequalityOperatorInPatternNotSupported or ErrorCode.ERR_DesignatorBeforePropertyPattern + or ErrorCode.ERR_CompilationUnitUnexpected => false, }; #pragma warning restore CS8524 // The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs index ae3515e5bb0d6..f86b54bbc27fd 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs @@ -5516,12 +5516,10 @@ private void AddNonTypeMembers( // Lang version check for ref-fields is done inside SourceMemberFieldSymbol; _ = fieldSyntax.Declaration.Type.SkipScoped(out _).SkipRefInField(out var refKind); - - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(fieldSyntax.Declaration.Variables.First().Identifier)); - } + reportMisplacedMemberInNamespace( + fieldSyntax, + fieldSyntax.Declaration.Variables.First().Identifier, + reportMisplacedGlobalCode); bool modifierErrors; var modifiers = SourceMemberFieldSymbol.MakeModifiers(this, fieldSyntax.Declaration.Variables[0].Identifier, fieldSyntax.Modifiers, isRefField: refKind != RefKind.None, diagnostics, out modifierErrors); @@ -5561,11 +5559,10 @@ private void AddNonTypeMembers( case SyntaxKind.MethodDeclaration: { var methodSyntax = (MethodDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(methodSyntax.Identifier)); - } + reportMisplacedMemberInNamespace( + methodSyntax, + methodSyntax.Identifier, + reportMisplacedGlobalCode); var method = SourceOrdinaryMethodSymbol.CreateMethodSymbol(this, bodyBinder, methodSyntax, compilation.IsNullableAnalysisEnabledIn(methodSyntax), diagnostics); builder.NonTypeMembersWithPartialImplementations.Add(method); @@ -5575,11 +5572,10 @@ private void AddNonTypeMembers( case SyntaxKind.ConstructorDeclaration: { var constructorSyntax = (ConstructorDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(constructorSyntax.Identifier)); - } + reportMisplacedMemberInNamespace( + constructorSyntax, + constructorSyntax.Identifier, + reportMisplacedGlobalCode); bool isNullableEnabled = compilation.IsNullableAnalysisEnabledIn(constructorSyntax); var constructor = SourceConstructorSymbol.CreateConstructorSymbol(this, constructorSyntax, isNullableEnabled, diagnostics); @@ -5594,11 +5590,10 @@ private void AddNonTypeMembers( case SyntaxKind.DestructorDeclaration: { var destructorSyntax = (DestructorDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(destructorSyntax.Identifier)); - } + reportMisplacedMemberInNamespace( + destructorSyntax, + destructorSyntax.Identifier, + reportMisplacedGlobalCode); // CONSIDER: if this doesn't (directly or indirectly) override object.Finalize, the // runtime won't consider it a finalizer and it will not be marked as a destructor @@ -5612,11 +5607,10 @@ private void AddNonTypeMembers( case SyntaxKind.PropertyDeclaration: { var propertySyntax = (PropertyDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(propertySyntax.Identifier)); - } + reportMisplacedMemberInNamespace( + propertySyntax, + propertySyntax.Identifier, + reportMisplacedGlobalCode); var property = SourcePropertySymbol.Create(this, bodyBinder, propertySyntax, diagnostics); builder.NonTypeMembersWithPartialImplementations.Add(property); @@ -5663,12 +5657,10 @@ private void AddNonTypeMembers( case SyntaxKind.EventFieldDeclaration: { var eventFieldSyntax = (EventFieldDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add( - ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(eventFieldSyntax.Declaration.Variables.First().Identifier)); - } + reportMisplacedMemberInNamespace( + eventFieldSyntax, + eventFieldSyntax.Declaration.Variables.First().Identifier, + reportMisplacedGlobalCode); foreach (VariableDeclaratorSyntax declarator in eventFieldSyntax.Declaration.Variables) { @@ -5717,11 +5709,10 @@ private void AddNonTypeMembers( case SyntaxKind.EventDeclaration: { var eventSyntax = (EventDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(eventSyntax.Identifier)); - } + reportMisplacedMemberInNamespace( + eventSyntax, + eventSyntax.Identifier, + reportMisplacedGlobalCode); var @event = new SourceCustomEventSymbol(this, bodyBinder, eventSyntax, diagnostics); @@ -5737,11 +5728,10 @@ private void AddNonTypeMembers( case SyntaxKind.IndexerDeclaration: { var indexerSyntax = (IndexerDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(indexerSyntax.ThisKeyword)); - } + reportMisplacedMemberInNamespace( + indexerSyntax, + indexerSyntax.ThisKeyword, + reportMisplacedGlobalCode); var indexer = SourcePropertySymbol.Create(this, bodyBinder, indexerSyntax, diagnostics); builder.HaveIndexers = true; @@ -5754,11 +5744,10 @@ private void AddNonTypeMembers( case SyntaxKind.ConversionOperatorDeclaration: { var conversionOperatorSyntax = (ConversionOperatorDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(conversionOperatorSyntax.OperatorKeyword)); - } + reportMisplacedMemberInNamespace( + conversionOperatorSyntax, + conversionOperatorSyntax.OperatorKeyword, + reportMisplacedGlobalCode); var method = SourceUserDefinedConversionSymbol.CreateUserDefinedConversionSymbol( this, bodyBinder, conversionOperatorSyntax, compilation.IsNullableAnalysisEnabledIn(conversionOperatorSyntax), diagnostics); @@ -5769,11 +5758,10 @@ private void AddNonTypeMembers( case SyntaxKind.OperatorDeclaration: { var operatorSyntax = (OperatorDeclarationSyntax)m; - if (IsImplicitClass && reportMisplacedGlobalCode) - { - diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected, - new SourceLocation(operatorSyntax.OperatorKeyword)); - } + reportMisplacedMemberInNamespace( + operatorSyntax, + operatorSyntax.OperatorKeyword, + reportMisplacedGlobalCode); var method = SourceUserDefinedOperatorSymbol.CreateUserDefinedOperatorSymbol( this, bodyBinder, operatorSyntax, compilation.IsNullableAnalysisEnabledIn(operatorSyntax), diagnostics); @@ -5849,6 +5837,18 @@ SyntaxKind.FileScopedNamespaceDeclaration or AddInitializers(builder.InstanceInitializers, instanceInitializers); AddInitializers(builder.StaticInitializers, staticInitializers); + + void reportMisplacedMemberInNamespace(SyntaxNode member, SyntaxToken locationSyntax, bool reportMisplacedGlobalCode) + { + if (IsImplicitClass && reportMisplacedGlobalCode) + { + var parentSyntax = member.Parent; + var errorCode = parentSyntax.IsKind(SyntaxKind.CompilationUnit) + ? ErrorCode.ERR_CompilationUnitUnexpected + : ErrorCode.ERR_NamespaceUnexpected; + diagnostics.Add(errorCode, new SourceLocation(locationSyntax)); + } + } } private void AddAccessorIfAvailable(ArrayBuilder symbols, MethodSymbol? accessorOpt) diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 902c41a875472..39b97efa96ea5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -567,6 +567,11 @@ Inicializátor kolekce má za následek nekonečný řetězec vytváření instancí kolekce '{0}'. + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' Parametr typu {1} má omezení unmanaged, takže není možné používat {1} jako omezení pro {0}. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 3181220ff976d..cc832bbc9e59a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -567,6 +567,11 @@ Der Sammlungsinitialisierer führt zu einer unendlichen Kette von Instanziierungen von Sammlungs- "{0}". + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' Der {1}-Typparameter enthält die Einschränkung "unmanaged". "{1}" kann daher nicht als Einschränkung für "{0}" verwendet werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 94e1df63b1483..63c1713972390 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -567,6 +567,11 @@ El inicializador de colecciones produce una cadena infinita de instancias de la colección "{0}". + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' El parámetro de tipo "{1}" tiene la restricción "unmanaged"; por tanto, "{1}" no se puede usar como restricción para "{0}" diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 95db0574ab778..2514cadd8555e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -567,6 +567,11 @@ L'initialiseur de collection donne lieu à une chaîne infinie d'instanciations de la collection « {0} ». + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' Le paramètre de type '{1}' a la contrainte 'unmanaged'. '{1}' ne peut donc pas être utilisé comme contrainte pour '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 33872f9024386..8e9ff5da71416 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -567,6 +567,11 @@ L'inizializzatore di raccolta genera una catena infinita di creazioni di istanze della raccolta '{0}'. + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' Il parametro di tipo '{1}' ha il vincolo 'managed'. Non è quindi possibile usare '{1}' come vincolo per '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index c846a8714ef79..f85cba504ee36 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -567,6 +567,11 @@ コレクション初期化子は、コレクション '{0}' のインスタンス化の無限チェーンになります。 + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' 型パラメーター '{1}' は 'unmanaged' 制約を含むので、'{0}' の制約として '{1}' を使用することはできません diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index e91ff1e66932c..8284244bdb176 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -567,6 +567,11 @@ 컬렉션 이니셜라이저를 사용하면 컬렉션 '{0}'의 인스턴스화 체인이 무한해집니다. + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' 형식 매개 변수 '{1}'에 'unmanaged' 제약 조건이 있으므로 '{1}'은(는) '{0}'에 대한 제약 조건으로 사용할 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 3b61b836aeb8d..da459cc5b6389 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -567,6 +567,11 @@ Inicjator kolekcji powoduje utworzenie nieskończonego łańcucha wystąpień kolekcji „{0}”. + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' Parametr typu „{1}” ma ograniczenie „unmanaged”, dlatego elementu „{1}” nie można użyć jako ograniczenia dla elementu „{0}” diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index b040dc68fd06f..90d782b7048e8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -567,6 +567,11 @@ O inicializador de coleção resulta em uma cadeia infinita de instanciações da coleção ''{0}''. + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' O parâmetro de tipo '{1}' tem a restrição 'unmanaged' e, por isso, '{1}' não pode ser usado como uma restrição de '{0}' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 43840fb83c8c5..92e130f888c1a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -567,6 +567,11 @@ Инициализатор коллекции приводит к созданию бесконечной цепочки экземпляров коллекции "{0}". + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' Параметр типа "{1}" имеет ограничение "unmanaged", поэтому "{1}" не может использоваться в качестве ограничения для "{0}". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index ad5294ff20891..493f7e2a553b5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -567,6 +567,11 @@ Koleksiyon başlatıcısı, '{0}' koleksiyonunun sonsuz sayıda örneklem zinciriyle sonuçlanır. + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' '{1}' tür parametresinde 'unmanaged' kısıtlaması olduğundan '{1}', '{0}' için kısıtlama olarak kullanılamaz diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 5a7a882ab546a..9cb1579f6b145 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -567,6 +567,11 @@ 集合初始值设定项会生成集合 ‘{0}’ 的无限实例化链。 + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' 类型参数“{1}”具有 "unmanaged" 约束,因此“{1}”不能用作“{0}”的约束 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index c36ef51a5e099..e10aaee051992 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -567,6 +567,11 @@ 集合初始設定式會導致集合 '{0}' 的無限具現化鏈結。 + + A compilation unit cannot directly contain members such as fields, methods or properties + A compilation unit cannot directly contain members such as fields, methods or properties + + Type parameter '{1}' has the 'unmanaged' constraint so '{1}' cannot be used as a constraint for '{0}' 類型參數 '{1}' 有 'unmanaged' 條件約束,因此 '{1}' 不可作為 '{0}' 的條件約束 diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs index 569b0f0cfb730..76d6cf0c09ad6 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/OutVarTests.cs @@ -30712,27 +30712,27 @@ public static bool TakeOutParam(T y, out T x) var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool b { get; } = H.TakeOutParam(1, out int x1); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "b").WithLocation(3, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "b").WithLocation(3, 6), // (4,9): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(4, 9), - // (7,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (7,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool d { get; } = H.TakeOutParam(2, out int x2); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "d").WithLocation(7, 6), - // (9,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "d").WithLocation(7, 6), + // (9,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool f { get; } = H.TakeOutParam(3, out int x3); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "f").WithLocation(9, 6), - // (12,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "f").WithLocation(9, 6), + // (12,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool h { get; } = H.Dummy(H.TakeOutParam(41, out int x4), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "h").WithLocation(12, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "h").WithLocation(12, 6), // (13,54): error CS0128: A local variable or function named 'x4' is already defined in this scope // H.TakeOutParam(42, out int x4)); Diagnostic(ErrorCode.ERR_LocalDuplicate, "x4").WithArguments("x4").WithLocation(13, 54), - // (15,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (15,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool x5 { get; } = - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "x5").WithLocation(15, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "x5").WithLocation(15, 6), // (20,13): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1, x2, x3, x4, x5); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(20, 13), @@ -30883,27 +30883,27 @@ public static bool TakeOutParam(T y, out T x) var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool b { get; } = H.TakeOutParam(1, out var x1); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "b").WithLocation(3, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "b").WithLocation(3, 6), // (4,9): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(4, 9), - // (7,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (7,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool d { get; } = H.TakeOutParam(2, out var x2); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "d").WithLocation(7, 6), - // (9,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "d").WithLocation(7, 6), + // (9,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool f { get; } = H.TakeOutParam(3, out var x3); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "f").WithLocation(9, 6), - // (12,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "f").WithLocation(9, 6), + // (12,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool h { get; } = H.Dummy(H.TakeOutParam(41, out var x4), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "h").WithLocation(12, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "h").WithLocation(12, 6), // (13,54): error CS0128: A local variable or function named 'x4' is already defined in this scope // H.TakeOutParam(42, out var x4)); Diagnostic(ErrorCode.ERR_LocalDuplicate, "x4").WithArguments("x4").WithLocation(13, 54), - // (15,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (15,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool x5 { get; } = - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "x5").WithLocation(15, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "x5").WithLocation(15, 6), // (20,13): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1, x2, x3, x4, x5); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(20, 13), @@ -31245,7 +31245,7 @@ public static System.Action TakeOutParam(T y, out T x) { var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); - int[] exclude = new int[] { (int)ErrorCode.ERR_NamespaceUnexpected }; + int[] exclude = new int[] { (int)ErrorCode.ERR_CompilationUnitUnexpected }; compilation.GetDiagnostics().Where(d => !exclude.Contains(d.Code)).Verify( // (4,9): error CS0103: The name 'x1' does not exist in the current context @@ -31418,7 +31418,7 @@ public static System.Action TakeOutParam(T y, out T x) { var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); - int[] exclude = new int[] { (int)ErrorCode.ERR_NamespaceUnexpected }; + int[] exclude = new int[] { (int)ErrorCode.ERR_CompilationUnitUnexpected }; compilation.GetDiagnostics().Where(d => !exclude.Contains(d.Code)).Verify( // (4,9): error CS0103: The name 'x1' does not exist in the current context @@ -32032,9 +32032,9 @@ public static int TakeOutParam(T y, out T x) var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,12): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,12): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // fixed bool a[2], b[H.TakeOutParam(1, out var x1)]; - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "a").WithLocation(3, 12), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "a").WithLocation(3, 12), // (3,18): error CS1642: Fixed size buffer fields may only be members of structs // fixed bool a[2], b[H.TakeOutParam(1, out var x1)]; Diagnostic(ErrorCode.ERR_FixedNotInStruct, "b").WithLocation(3, 18), diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/PatternMatchingTests_Global.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/PatternMatchingTests_Global.cs index 74ce4ad273c82..a0313e2a86574 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/PatternMatchingTests_Global.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/PatternMatchingTests_Global.cs @@ -4935,27 +4935,27 @@ class H var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool b { get; } = (1 is int x1); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "b").WithLocation(3, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "b").WithLocation(3, 6), // (4,9): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(4, 9), - // (7,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (7,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool d { get; } = (2 is int x2); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "d").WithLocation(7, 6), - // (9,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "d").WithLocation(7, 6), + // (9,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool f { get; } = (3 is int x3); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "f").WithLocation(9, 6), - // (12,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "f").WithLocation(9, 6), + // (12,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool h { get; } = H.Dummy((41 is int x4), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "h").WithLocation(12, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "h").WithLocation(12, 6), // (13,38): error CS0128: A local variable or function named 'x4' is already defined in this scope // (42 is int x4)); Diagnostic(ErrorCode.ERR_LocalDuplicate, "x4").WithArguments("x4").WithLocation(13, 38), - // (15,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (15,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool x5 { get; } = - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "x5").WithLocation(15, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "x5").WithLocation(15, 6), // (20,13): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1, x2, x3, x4, x5); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(20, 13), @@ -5101,27 +5101,27 @@ class H var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool b { get; } = (1 is var x1); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "b").WithLocation(3, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "b").WithLocation(3, 6), // (4,9): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(4, 9), - // (7,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (7,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool d { get; } = (2 is var x2); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "d").WithLocation(7, 6), - // (9,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "d").WithLocation(7, 6), + // (9,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool f { get; } = (3 is var x3); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "f").WithLocation(9, 6), - // (12,6): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "f").WithLocation(9, 6), + // (12,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool h { get; } = H.Dummy((41 is var x4), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "h").WithLocation(12, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "h").WithLocation(12, 6), // (13,38): error CS0128: A local variable or function named 'x4' is already defined in this scope // (42 is var x4)); Diagnostic(ErrorCode.ERR_LocalDuplicate, "x4").WithArguments("x4").WithLocation(13, 38), - // (15,6): error CS0116: A namespace cannot directly contain members such as fields or methods + // (15,6): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // bool x5 { get; } = - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "x5").WithLocation(15, 6), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "x5").WithLocation(15, 6), // (20,13): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1, x2, x3, x4, x5); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(20, 13), @@ -5432,30 +5432,30 @@ class H var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action b = H.Dummy(1 is int x1); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "b").WithLocation(3, 21), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "b").WithLocation(3, 21), // (4,9): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(4, 9), - // (7,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (7,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action d = H.Dummy(2 is int x2); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "d").WithLocation(7, 21), - // (9,21): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "d").WithLocation(7, 21), + // (9,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action f = H.Dummy(3 is int x3); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "f").WithLocation(9, 21), - // (12,21): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "f").WithLocation(9, 21), + // (12,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action h = H.Dummy((41 is int x4), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "h").WithLocation(12, 21), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "h").WithLocation(12, 21), // (13,36): error CS0128: A local variable or function named 'x4' is already defined in this scope // (42 is int x4)); Diagnostic(ErrorCode.ERR_LocalDuplicate, "x4").WithArguments("x4").WithLocation(13, 36), - // (15,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (15,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action x5 = - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "x5").WithLocation(15, 21), - // (18,21): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "x5").WithLocation(15, 21), + // (18,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action i = H.Dummy(5 is int x6), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "i").WithLocation(18, 21), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "i").WithLocation(18, 21), // (21,6): warning CS8321: The local function 'Test' is declared but never used // void Test() Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "Test").WithArguments("Test").WithLocation(21, 6), @@ -5617,30 +5617,30 @@ class H var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action b = H.Dummy(1 is var x1); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "b").WithLocation(3, 21), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "b").WithLocation(3, 21), // (4,9): error CS0103: The name 'x1' does not exist in the current context // H.Dummy(x1); Diagnostic(ErrorCode.ERR_NameNotInContext, "x1").WithArguments("x1").WithLocation(4, 9), - // (7,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (7,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action d = H.Dummy(2 is var x2); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "d").WithLocation(7, 21), - // (9,21): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "d").WithLocation(7, 21), + // (9,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action f = H.Dummy(3 is var x3); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "f").WithLocation(9, 21), - // (12,21): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "f").WithLocation(9, 21), + // (12,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action h = H.Dummy((41 is var x4), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "h").WithLocation(12, 21), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "h").WithLocation(12, 21), // (13,36): error CS0128: A local variable or function named 'x4' is already defined in this scope // (42 is var x4)); Diagnostic(ErrorCode.ERR_LocalDuplicate, "x4").WithArguments("x4").WithLocation(13, 36), - // (15,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (15,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action x5 = - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "x5").WithLocation(15, 21), - // (18,21): error CS0116: A namespace cannot directly contain members such as fields or methods + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "x5").WithLocation(15, 21), + // (18,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action i = H.Dummy(5 is var x6), - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "i").WithLocation(18, 21), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "i").WithLocation(18, 21), // (21,6): warning CS8321: The local function 'Test' is declared but never used // void Test() Diagnostic(ErrorCode.WRN_UnreferencedLocalFunction, "Test").WithArguments("Test").WithLocation(21, 6), @@ -6208,9 +6208,9 @@ class H var compilation = CreateCompilationWithMscorlib461(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9); compilation.VerifyDiagnostics( - // (3,12): error CS0116: A namespace cannot directly contain members such as fields or methods + // (3,12): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // fixed bool a[2], b[H.Dummy(1 is var x1)]; - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "a").WithLocation(3, 12), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "a").WithLocation(3, 12), // (3,18): error CS1642: Fixed size buffer fields may only be members of structs // fixed bool a[2], b[H.Dummy(1 is var x1)]; Diagnostic(ErrorCode.ERR_FixedNotInStruct, "b").WithLocation(3, 18), diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs index f48acfbe61dc1..6701cd7295977 100644 --- a/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs @@ -65,9 +65,9 @@ record Point(int x, int y); // (2,1): error CS0246: The type or namespace name 'record' could not be found (are you missing a using directive or an assembly reference?) // record Point { } Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "record").WithArguments("record").WithLocation(2, 1), - // (2,8): error CS0116: A namespace cannot directly contain members such as fields or methods + // (2,8): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // record Point { } - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "Point").WithLocation(2, 8), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "Point").WithLocation(2, 8), // (2,8): error CS0548: '.Point': property or indexer must have at least one accessor // record Point { } Diagnostic(ErrorCode.ERR_PropertyWithNoAccessors, "Point").WithArguments(".Point").WithLocation(2, 8) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index a59aa73a8031c..4aea9bf02a2d8 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -11808,9 +11808,9 @@ public void TypeScopeModifier_02_CSharp10() // (1,8): error CS0118: 'record' is a variable but is used like a type // scoped record A { } Diagnostic(ErrorCode.ERR_BadSKknown, "record").WithArguments("record", "variable", "type").WithLocation(1, 8), - // (1,15): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // (1,15): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // scoped record A { } - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "A").WithLocation(1, 15), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "A").WithLocation(1, 15), // (1,15): error CS0106: The modifier 'scoped' is not valid for this item // scoped record A { } Diagnostic(ErrorCode.ERR_BadMemberFlag, "A").WithArguments("scoped").WithLocation(1, 15), @@ -11854,9 +11854,9 @@ public void TypeScopeModifier_02_CSharp11() // (1,8): error CS0118: 'record' is a variable but is used like a type // scoped record A { } Diagnostic(ErrorCode.ERR_BadSKknown, "record").WithArguments("record", "variable", "type").WithLocation(1, 8), - // (1,15): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // (1,15): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // scoped record A { } - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "A").WithLocation(1, 15), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "A").WithLocation(1, 15), // (1,15): error CS0106: The modifier 'scoped' is not valid for this item // scoped record A { } Diagnostic(ErrorCode.ERR_BadMemberFlag, "A").WithArguments("scoped").WithLocation(1, 15), diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index 1dd5864c414d2..d5da3ff399b4e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -2749,7 +2749,7 @@ void Method(string str) // CS0116 "; DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(test, new ErrorDescription { Code = (int)ErrorCode.ERR_NamespaceUnexpected, Line = 5, Column = 10 }, - new ErrorDescription { Code = (int)ErrorCode.ERR_NamespaceUnexpected, Line = 10, Column = 5 }); + new ErrorDescription { Code = (int)ErrorCode.ERR_CompilationUnitUnexpected, Line = 10, Column = 5 }); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs index d85199441bae9..ed78fc7d1fc76 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs @@ -737,18 +737,18 @@ public void LocalDeclarationStatement_02() var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyDiagnostics( - // (2,12): error CS0116: A namespace cannot directly contain members such as fields or methods + // (2,12): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // new string a = "Hi!"; - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "a").WithLocation(2, 12), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "a").WithLocation(2, 12), // (2,12): warning CS0109: The member '.a' does not hide an accessible member. The new keyword is not required. // new string a = "Hi!"; Diagnostic(ErrorCode.WRN_NewNotRequired, "a").WithArguments(".a").WithLocation(2, 12), // (3,26): error CS0103: The name 'a' does not exist in the current context // System.Console.WriteLine(a); Diagnostic(ErrorCode.ERR_NameNotInContext, "a").WithArguments("a").WithLocation(3, 26), - // (4,15): error CS0116: A namespace cannot directly contain members such as fields or methods + // (4,15): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // public string b = "Hi!"; - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "b").WithLocation(4, 15), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "b").WithLocation(4, 15), // (5,26): error CS0103: The name 'b' does not exist in the current context // System.Console.WriteLine(b); Diagnostic(ErrorCode.ERR_NameNotInContext, "b").WithArguments("b").WithLocation(5, 26), @@ -2609,9 +2609,9 @@ public void Scope_09() var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyDiagnostics( - // (5,10): error CS0116: A namespace cannot directly contain members such as fields or methods + // (5,10): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // new void M() - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "M").WithLocation(5, 10), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "M").WithLocation(5, 10), // (5,10): warning CS0109: The member '.M()' does not hide an accessible member. The new keyword is not required. // new void M() Diagnostic(ErrorCode.WRN_NewNotRequired, "M").WithArguments(".M()").WithLocation(5, 10) @@ -2640,9 +2640,9 @@ public static int GetInt(out int v) var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyDiagnostics( - // (5,9): error CS0116: A namespace cannot directly contain members such as fields or methods + // (5,9): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // new int F = C1.GetInt(out var Test); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "F").WithLocation(5, 9), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "F").WithLocation(5, 9), // (5,9): warning CS0109: The member '.F' does not hide an accessible member. The new keyword is not required. // new int F = C1.GetInt(out var Test); Diagnostic(ErrorCode.WRN_NewNotRequired, "F").WithArguments(".F").WithLocation(5, 9) @@ -2665,9 +2665,9 @@ public void Scope_11() var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyDiagnostics( - // (5,10): error CS0116: A namespace cannot directly contain members such as fields or methods + // (5,10): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // new void M() - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "M").WithLocation(5, 10), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "M").WithLocation(5, 10), // (5,10): warning CS0109: The member '.M()' does not hide an accessible member. The new keyword is not required. // new void M() Diagnostic(ErrorCode.WRN_NewNotRequired, "M").WithArguments(".M()").WithLocation(5, 10) @@ -4399,9 +4399,9 @@ public void LocalFunctionStatement_04() var comp = CreateCompilation(text, options: TestOptions.DebugExe, parseOptions: DefaultParseOptions); comp.VerifyDiagnostics( - // (2,10): error CS0116: A namespace cannot directly contain members such as fields or methods + // (2,10): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // new void localA() => System.Console.WriteLine(); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "localA").WithLocation(2, 10), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "localA").WithLocation(2, 10), // (2,10): warning CS0109: The member '.localA()' does not hide an accessible member. The new keyword is not required. // new void localA() => System.Console.WriteLine(); Diagnostic(ErrorCode.WRN_NewNotRequired, "localA").WithArguments(".localA()").WithLocation(2, 10), @@ -4411,27 +4411,27 @@ public void LocalFunctionStatement_04() // (4,1): error CS0106: The modifier 'public' is not valid for this item // public void localB() => System.Console.WriteLine(); Diagnostic(ErrorCode.ERR_BadMemberFlag, "public").WithArguments("public").WithLocation(4, 1), - // (6,14): error CS0116: A namespace cannot directly contain members such as fields or methods + // (6,14): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // virtual void localC() => System.Console.WriteLine(); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "localC").WithLocation(6, 14), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "localC").WithLocation(6, 14), // (6,14): error CS0621: '.localC()': virtual or abstract members cannot be private // virtual void localC() => System.Console.WriteLine(); Diagnostic(ErrorCode.ERR_VirtualPrivate, "localC").WithArguments(".localC()").WithLocation(6, 14), // (7,1): error CS0103: The name 'localC' does not exist in the current context // localC(); Diagnostic(ErrorCode.ERR_NameNotInContext, "localC").WithArguments("localC").WithLocation(7, 1), - // (8,13): error CS0116: A namespace cannot directly contain members such as fields or methods + // (8,13): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // sealed void localD() => System.Console.WriteLine(); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "localD").WithLocation(8, 13), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "localD").WithLocation(8, 13), // (8,13): error CS0238: '.localD()' cannot be sealed because it is not an override // sealed void localD() => System.Console.WriteLine(); Diagnostic(ErrorCode.ERR_SealedNonOverride, "localD").WithArguments(".localD()").WithLocation(8, 13), // (9,1): error CS0103: The name 'localD' does not exist in the current context // localD(); Diagnostic(ErrorCode.ERR_NameNotInContext, "localD").WithArguments("localD").WithLocation(9, 1), - // (10,15): error CS0116: A namespace cannot directly contain members such as fields or methods + // (10,15): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // override void localE() => System.Console.WriteLine(); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "localE").WithLocation(10, 15), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "localE").WithLocation(10, 15), // (10,15): error CS0621: '.localE()': virtual or abstract members cannot be private // override void localE() => System.Console.WriteLine(); Diagnostic(ErrorCode.ERR_VirtualPrivate, "localE").WithArguments(".localE()").WithLocation(10, 15), @@ -4441,9 +4441,9 @@ public void LocalFunctionStatement_04() // (11,1): error CS0103: The name 'localE' does not exist in the current context // localE(); Diagnostic(ErrorCode.ERR_NameNotInContext, "localE").WithArguments("localE").WithLocation(11, 1), - // (12,15): error CS0116: A namespace cannot directly contain members such as fields or methods + // (12,15): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // abstract void localF() => System.Console.WriteLine(); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "localF").WithLocation(12, 15), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "localF").WithLocation(12, 15), // (12,15): error CS0500: '.localF()' cannot declare a body because it is marked abstract // abstract void localF() => System.Console.WriteLine(); Diagnostic(ErrorCode.ERR_AbstractHasBody, "localF").WithArguments(".localF()").WithLocation(12, 15), @@ -4453,9 +4453,9 @@ public void LocalFunctionStatement_04() // (13,1): error CS0103: The name 'localF' does not exist in the current context // localF(); Diagnostic(ErrorCode.ERR_NameNotInContext, "localF").WithArguments("localF").WithLocation(13, 1), - // (14,14): error CS0116: A namespace cannot directly contain members such as fields or methods + // (14,14): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // partial void localG() => System.Console.WriteLine(); - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "localG").WithLocation(14, 14), + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "localG").WithLocation(14, 14), // (14,14): error CS0759: No defining declaration found for implementing declaration of partial method '.localG()' // partial void localG() => System.Console.WriteLine(); Diagnostic(ErrorCode.ERR_PartialMethodMustHaveLatent, "localG").WithArguments(".localG()").WithLocation(14, 14), @@ -4816,9 +4816,9 @@ public void PropertyDeclaration_01() // (2,5): error CS0103: The name 'local' does not exist in the current context // _ = local; Diagnostic(ErrorCode.ERR_NameNotInContext, "local").WithArguments("local").WithLocation(2, 5), - // (4,5): error CS0116: A namespace cannot directly contain members such as fields or methods + // (4,5): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // int local => 1; - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "local").WithLocation(4, 5) + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "local").WithLocation(4, 5) ); } @@ -4837,9 +4837,9 @@ public void PropertyDeclaration_02() // (2,5): error CS0103: The name 'local' does not exist in the current context // _ = local; Diagnostic(ErrorCode.ERR_NameNotInContext, "local").WithArguments("local").WithLocation(2, 5), - // (4,5): error CS0116: A namespace cannot directly contain members such as fields or methods + // (4,5): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // int local { get => 1; } - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "local").WithLocation(4, 5) + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "local").WithLocation(4, 5) ); } @@ -4858,9 +4858,9 @@ public void PropertyDeclaration_03() // (2,5): error CS0103: The name 'local' does not exist in the current context // _ = local; Diagnostic(ErrorCode.ERR_NameNotInContext, "local").WithArguments("local").WithLocation(2, 5), - // (4,5): error CS0116: A namespace cannot directly contain members such as fields or methods + // (4,5): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // int local { get { return 1; } } - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "local").WithLocation(4, 5) + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "local").WithLocation(4, 5) ); } @@ -4879,9 +4879,9 @@ public void EventDeclaration_01() // (2,1): error CS0103: The name 'local' does not exist in the current context // local += null; Diagnostic(ErrorCode.ERR_NameNotInContext, "local").WithArguments("local").WithLocation(2, 1), - // (4,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (4,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action local; - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "local").WithLocation(4, 21) + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "local").WithLocation(4, 21) ); } @@ -4904,9 +4904,9 @@ event System.Action local // (2,1): error CS0103: The name 'local' does not exist in the current context // local -= null; Diagnostic(ErrorCode.ERR_NameNotInContext, "local").WithArguments("local").WithLocation(2, 1), - // (4,21): error CS0116: A namespace cannot directly contain members such as fields or methods + // (4,21): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties // event System.Action local - Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "local").WithLocation(4, 21) + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "local").WithLocation(4, 21) ); } @@ -9960,5 +9960,249 @@ partial class Program comp = CreateCompilation(new[] { src2, src1 }, options: TestOptions.ReleaseExe); CompileAndVerify(comp, expectedOutput: "Done").VerifyDiagnostics(); } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestFieldInCompilationUnit() + { + var source = """ + private int f; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: DefaultParseOptions); + comp.VerifyDiagnostics( + // (1,13): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties + // private int f; + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "f").WithLocation(1, 13) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestFieldInNamespace() + { + var source = """ + namespace N; + + private int f; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (3,13): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // private int f; + Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "f").WithLocation(3, 13) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestPropertyInCompilationUnit() + { + var source = """ + int P { get; set; } + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: DefaultParseOptions); + comp.VerifyDiagnostics( + // (1,5): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties + // int P { get; set; } + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "P").WithLocation(1, 5) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestPropertyInNamespace() + { + var source = """ + namespace N; + + int P { get; set; } + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (3,5): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // int P { get; set; } + Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "P").WithLocation(3, 5) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestEventFieldInCompilationUnit() + { + var source = """ + using System; + + event Action E; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: DefaultParseOptions); + comp.VerifyDiagnostics( + // (3,14): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties + // event Action E; + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "E").WithLocation(3, 14) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestEventFieldInNamespace() + { + var source = """ + using System; + + namespace N; + + event Action E; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (5,14): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // event Action E; + Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "E").WithLocation(5, 14) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestEventDeclarationInCompilationUnit() + { + var source = """ + using System; + + event Action E { add { } remove { } } + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: DefaultParseOptions); + comp.VerifyDiagnostics( + // (3,14): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties + // event Action E { add { } remove { } } + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "E").WithLocation(3, 14) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestEventDeclarationInNamespace() + { + var source = """ + using System; + + namespace N; + + event Action E { add { } remove { } } + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (5,14): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // event Action E { add { } remove { } } + Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "E").WithLocation(5, 14) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestIndexerInCompilationUnit() + { + var source = """ + int this[int x] => 0; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: DefaultParseOptions); + comp.VerifyDiagnostics( + // (1,5): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties + // int this[int x] => 0; + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "this").WithLocation(1, 5) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestIndexerInNamespace() + { + var source = """ + namespace N; + + int this[int x] => 0; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (3,5): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // int this[int x] => 0; + Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "this").WithLocation(3, 5) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestConversionOperatorInCompilationUnit() + { + var source = """ + public static implicit operator int(int d) => 0; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: DefaultParseOptions); + comp.VerifyDiagnostics( + // (1,24): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties + // public static implicit operator int(int d) => 0; + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "operator").WithLocation(1, 24), + // (1,33): error CS0556: User-defined conversion must convert to or from the enclosing type + // public static implicit operator int(int d) => 0; + Diagnostic(ErrorCode.ERR_ConversionNotInvolvingContainedType, "int").WithLocation(1, 33) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestConversionOperatorInNamespace() + { + var source = """ + namespace N; + + public static implicit operator int(int d) => 0; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (3,24): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // public static implicit operator int(int d) => 0; + Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "operator").WithLocation(3, 24), + // (3,33): error CS0556: User-defined conversion must convert to or from the enclosing type + // public static implicit operator int(int d) => 0; + Diagnostic(ErrorCode.ERR_ConversionNotInvolvingContainedType, "int").WithLocation(3, 33) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestOperatorInCompilationUnit() + { + var source = """ + public static int operator +(int operand1, int operand2) => 0; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: DefaultParseOptions); + comp.VerifyDiagnostics( + // (1,19): error CS9348: A compilation unit cannot directly contain members such as fields, methods or properties + // public static int operator +(int operand1, int operand2) => 0; + Diagnostic(ErrorCode.ERR_CompilationUnitUnexpected, "operator").WithLocation(1, 19), + // (1,28): error CS0563: One of the parameters of a binary operator must be the containing type + // public static int operator +(int operand1, int operand2) => 0; + Diagnostic(ErrorCode.ERR_BadBinaryOperatorSignature, "+").WithLocation(1, 28) + ); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81141")] + public void TestOperatorInFileScopedNamespace() + { + var source = """ + namespace N; + + public static int operator +(int operand1, int operand2) => 0; + """; + + var comp = CreateCompilation(source, options: TestOptions.DebugDll, parseOptions: TestOptions.Regular10); + comp.VerifyDiagnostics( + // (3,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements + // public static int operator +(int operand1, int operand2) => 0; + Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "operator").WithLocation(3, 19), + // (3,28): error CS0563: One of the parameters of a binary operator must be the containing type + // public static int operator +(int operand1, int operand2) => 0; + Diagnostic(ErrorCode.ERR_BadBinaryOperatorSignature, "+").WithLocation(3, 28) + ); + } } }