diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md
index 18eeade68239a..35f47129692cb 100644
--- a/.github/copilot-instructions.md
+++ b/.github/copilot-instructions.md
@@ -75,6 +75,7 @@ var symbolInfo = semanticModel.GetSymbolInfo(expression);
- **Cancellation**: Always thread `CancellationToken` through async operations
- **MEF Lifecycle**: Use `[ImportingConstructor]` with obsolete attribute for MEF v2 compatibility
- **PROTOTYPE Comments**: Only used to track follow-up work in feature branches and are disallowed in main branch
+- **Code Formatting**: Avoid trailing spaces and blank lines (lines with only whitespace). Ensure all lines either have content or are completely empty.
## Common Gotchas
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx
index b4b9c076fbbd6..616607690ae92 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.resx
+++ b/src/Compilers/CSharp/Portable/CSharpResources.resx
@@ -6567,6 +6567,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
Unexpected argument list.
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
A constructor declared in a type with parameter list must have 'this' constructor initializer.
diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
index ad93cbed18c23..912ef255ec070 100644
--- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
@@ -2440,6 +2440,8 @@ internal enum ErrorCode
ERR_SingleInapplicableUnaryOperator = 9341,
ERR_AmbigOperator = 9342,
+ ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList = 9343,
+
// Note: you will need to do the following after adding errors:
// 1) Update ErrorFacts.IsBuildOnlyDiagnostic (src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs)
// 2) Add message to CSharpResources.resx
diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
index e1b55ba3daa84..34d8db1fcba80 100644
--- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
+++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
@@ -2547,6 +2547,7 @@ or ErrorCode.ERR_AmbigExtension
or ErrorCode.ERR_SingleInapplicableBinaryOperator
or ErrorCode.ERR_SingleInapplicableUnaryOperator
or ErrorCode.ERR_AmbigOperator
+ or ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList
=> 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/SourceNamedTypeSymbol_Bases.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
index c5f82cc3996af..5f0f37725756c 100644
--- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
+++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol_Bases.cs
@@ -27,7 +27,7 @@ internal partial class SourceNamedTypeSymbol
private ImmutableArray _lazyInterfaces;
///
- /// Gets the BaseType of this type. If the base type could not be determined, then
+ /// Gets the BaseType of this type. If the base type could not be determined, then
/// an instance of ErrorType is returned. If this kind of type does not have a base type
/// (for example, interfaces), null is returned. Also the special class System.Object
/// always has a BaseType of null.
@@ -637,10 +637,16 @@ private Tuple> MakeOneDeclaredB
void checkPrimaryConstructorBaseType(BaseTypeSyntax baseTypeSyntax, TypeSymbol baseType)
{
- if (baseTypeSyntax is PrimaryConstructorBaseTypeSyntax primaryConstructorBaseType &&
- (TypeKind != TypeKind.Class || baseType.TypeKind == TypeKind.Interface || ((TypeDeclarationSyntax)decl.SyntaxReference.GetSyntax()).ParameterList is null))
+ if (baseTypeSyntax is PrimaryConstructorBaseTypeSyntax primaryConstructorBaseType)
{
- diagnostics.Add(ErrorCode.ERR_UnexpectedArgumentList, primaryConstructorBaseType.ArgumentList.Location);
+ if (TypeKind != TypeKind.Class || baseType.TypeKind == TypeKind.Interface)
+ {
+ diagnostics.Add(ErrorCode.ERR_UnexpectedArgumentList, primaryConstructorBaseType.ArgumentList.Location);
+ }
+ else if (((TypeDeclarationSyntax)decl.SyntaxReference.GetSyntax()).ParameterList is null)
+ {
+ diagnostics.Add(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, primaryConstructorBaseType.ArgumentList.Location);
+ }
}
}
}
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
index 0fee9eae6d5b6..28783c923fbd8 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Neočekávaný seznam parametrů.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
index 6adc8fbaf373e..faf714b8069bf 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Unerwartete Parameterliste.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
index 88a84407eb3bd..362e938e3252e 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Lista de parámetros inesperada.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
index f39d4aea1e56a..a52b8bcc007de 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Liste de paramètres inattendue.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
index 8429c78c0e20f..e7db445512467 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Elenco parametri imprevisto.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
index d7469555b0568..89f102c4bca86 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.予期しないパラメーター リストです。
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
index bd9d92da9e968..9faa90271d2b7 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.예기치 않은 매개 변수 목록입니다.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
index ebc28c8f661ee..1bbfcbfdd0b72 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Nieoczekiwana lista parametrów.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
index ec7f0024ebbf8..833aae2ab17de 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Lista de parâmetros inesperada.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
index 343980a1a3c35..0d4229883fdb6 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Неожиданный список параметров.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
index ea4d26823b5bb..9ccd9991c0171 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.Beklenmeyen parametre listesi.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
index c2eebbb836bd2..a8ca62aba496e 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.意外的参数列表。
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
index 395d221ce82b4..6b8f4cacff6bd 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
@@ -2562,6 +2562,11 @@
The type parameter `{0}` is not referenced by either the extension parameter or a parameter of this member
+
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+ Cannot pass arguments to the base type without a parameter list on the type declaration.
+
+ Unexpected parameter list.未預期的參數清單。
diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/PrimaryConstructorTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/PrimaryConstructorTests.cs
index a8b294a1de635..3cde4131bd66b 100644
--- a/src/Compilers/CSharp/Test/Emit3/Semantics/PrimaryConstructorTests.cs
+++ b/src/Compilers/CSharp/Test/Emit3/Semantics/PrimaryConstructorTests.cs
@@ -72,37 +72,144 @@ public void LanguageVersion_01([CombinatorialValues("class ", "struct")] string
}
[Theory]
- [InlineData("class", "class")]
- [InlineData("struct", "interface")]
- public void LanguageVersion_02(string typeKeyword, string baseKeyword)
+ [InlineData(LanguageVersion.CSharp11)]
+ [InlineData(LanguageVersion.CSharp12)]
+ [InlineData(LanguageVersion.Preview)]
+ public void LanguageVersion_02_ClassClass(LanguageVersion languageVersion)
{
var src1 = @"
-" + typeKeyword + @" Point :
+class Point :
Base()
{}
-" + baseKeyword + @" Base{}
+class Base{}
";
- var comp = CreateCompilation(src1, parseOptions: TestOptions.Regular11, options: TestOptions.ReleaseDll);
- comp.VerifyDiagnostics(
- // (3,5): error CS8861: Unexpected argument list.
- // Base()
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(3, 5)
- );
- comp = CreateCompilation(src1, parseOptions: TestOptions.Regular12, options: TestOptions.ReleaseDll);
- comp.VerifyDiagnostics(
- // (3,5): error CS8861: Unexpected argument list.
- // Base()
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(3, 5)
- );
+ CreateCompilation(src1, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion), options: TestOptions.ReleaseDll)
+ .VerifyDiagnostics(
+ // (3,5): error CS9343: Cannot pass arguments to the base type without a parameter list on the type declaration.
+ // Base()
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "()").WithLocation(3, 5));
+ }
- comp = CreateCompilation(src1, options: TestOptions.ReleaseDll);
- comp.VerifyDiagnostics(
- // (3,5): error CS8861: Unexpected argument list.
+ [Fact]
+ public void TestEnumClass()
+ {
+ var src1 = """
+ enum Point :
+ Base()
+ {}
+
+ class Base{}
+ """;
+
+ CreateCompilation(src1).VerifyDiagnostics(
+ // (3,1): error CS1008: Type byte, sbyte, short, ushort, int, uint, long, or ulong expected
// Base()
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(3, 5)
- );
+ Diagnostic(ErrorCode.ERR_IntegralTypeExpected, "Base").WithLocation(2, 1),
+ // (3,5): error CS1514: { expected
+ // Base()
+ Diagnostic(ErrorCode.ERR_LbraceExpected, "(").WithLocation(2, 5),
+ // (3,5): error CS1513: } expected
+ // Base()
+ Diagnostic(ErrorCode.ERR_RbraceExpected, "(").WithLocation(2, 5),
+ // (3,5): error CS8803: Top-level statements must precede namespace and type declarations.
+ // Base()
+ Diagnostic(ErrorCode.ERR_TopLevelStatementAfterNamespaceOrType, @"()
+").WithLocation(2, 5),
+ // (3,6): error CS1525: Invalid expression term ')'
+ // Base()
+ Diagnostic(ErrorCode.ERR_InvalidExprTerm, ")").WithArguments(")").WithLocation(2, 6),
+ // (3,7): error CS1002: ; expected
+ // Base()
+ Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(2, 7));
+ }
+
+ [Theory]
+ [InlineData(LanguageVersion.CSharp11)]
+ [InlineData(LanguageVersion.CSharp12)]
+ [InlineData(LanguageVersion.Preview)]
+ public void LanguageVersion_02_ClassInterface(LanguageVersion languageVersion)
+ {
+ var src1 = """
+ class Point :
+ Base()
+ {}
+
+ interface Base{}
+ """;
+
+ CreateCompilation(src1, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion), options: TestOptions.ReleaseDll)
+ .VerifyDiagnostics(
+ // (2,5): error CS8861: Unexpected argument list.
+ // Base()
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(2, 5));
+ }
+
+ [Theory]
+ [InlineData(LanguageVersion.CSharp11)]
+ [InlineData(LanguageVersion.CSharp12)]
+ [InlineData(LanguageVersion.Preview)]
+ public void LanguageVersion_02_StructInterface(LanguageVersion languageVersion)
+ {
+ var src1 = """
+ struct Point :
+ Base()
+ {}
+
+ interface Base{}
+ """;
+
+ CreateCompilation(src1, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion), options: TestOptions.ReleaseDll)
+ .VerifyDiagnostics(
+ // (3,5): error CS8861: Unexpected argument list.
+ // Base()
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(2, 5));
+ }
+
+ [Theory]
+ [InlineData(LanguageVersion.CSharp11)]
+ [InlineData(LanguageVersion.CSharp12)]
+ [InlineData(LanguageVersion.Preview)]
+ public void LanguageVersion_02_StructClass(LanguageVersion languageVersion)
+ {
+ var src1 = """
+ struct Point :
+ Base()
+ {}
+
+ class Base{}
+ """;
+
+ CreateCompilation(src1, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion), options: TestOptions.ReleaseDll)
+ .VerifyDiagnostics(
+ // (2,1): error CS0527: Type 'Base' in interface list is not an interface
+ // Base()
+ Diagnostic(ErrorCode.ERR_NonInterfaceInInterfaceList, "Base").WithArguments("Base").WithLocation(2, 1),
+ // (2,5): error CS8861: Unexpected argument list.
+ // Base()
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(2, 5));
+ }
+
+ [Theory]
+ [InlineData(LanguageVersion.CSharp11)]
+ [InlineData(LanguageVersion.CSharp12)]
+ [InlineData(LanguageVersion.Preview)]
+ public void LanguageVersion_02_ClassStruct(LanguageVersion languageVersion)
+ {
+ var src1 = """
+ class Point :
+ Base()
+ {}
+
+ struct Base{}
+ """;
+
+ CreateCompilation(src1, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion), options: TestOptions.ReleaseDll)
+ .VerifyDiagnostics(
+ // (2,1): error CS0509: 'Point': cannot derive from sealed type 'Base'
+ // Base()
+ Diagnostic(ErrorCode.ERR_CantDeriveFromSealedType, "Base").WithArguments("Point", "Base").WithLocation(2, 1));
}
[Theory]
@@ -265,41 +372,64 @@ interface Base{}
);
}
- [Theory]
- [InlineData("class", "class")]
- [InlineData("struct", "interface")]
- public void LanguageVersion_06(string typeKeyword, string baseKeyword)
+ [Fact]
+ public void LanguageVersion_06_ClassClass()
{
var src1 = @"
-" + typeKeyword + @" Point
+class Point
: Base()
;
-" + baseKeyword + @" Base{}
+class Base{}
";
- var comp = CreateCompilation(src1, parseOptions: TestOptions.Regular11, options: TestOptions.ReleaseDll);
- comp.VerifyDiagnostics(
- // (3,7): error CS8861: Unexpected argument list.
+
+ CreateCompilation(src1, parseOptions: TestOptions.Regular11, options: TestOptions.ReleaseDll).VerifyDiagnostics(
+ // (3,7): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// : Base()
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(3, 7),
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "()").WithLocation(3, 7),
// (4,1): error CS9058: Feature 'primary constructors' is not available in C# 11.0. Please use language version 12.0 or greater.
// ;
- Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion11, ";").WithArguments("primary constructors", "12.0").WithLocation(4, 1)
- );
+ Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion11, ";").WithArguments("primary constructors", "12.0").WithLocation(4, 1));
- comp = CreateCompilation(src1, parseOptions: TestOptions.Regular12, options: TestOptions.ReleaseDll);
- comp.VerifyDiagnostics(
- // (3,7): error CS8861: Unexpected argument list.
+ CreateCompilation(src1, parseOptions: TestOptions.Regular12, options: TestOptions.ReleaseDll).VerifyDiagnostics(
+ // (3,7): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// : Base()
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(3, 7)
- );
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "()").WithLocation(3, 7));
- comp = CreateCompilation(src1, options: TestOptions.ReleaseDll);
- comp.VerifyDiagnostics(
- // (3,7): error CS8861: Unexpected argument list.
+ CreateCompilation(src1, options: TestOptions.ReleaseDll).VerifyDiagnostics(
+ // (3,7): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// : Base()
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(3, 7)
- );
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "()").WithLocation(3, 7));
+ }
+
+ [Fact]
+ public void LanguageVersion_06_StructInterface()
+ {
+ var src1 = """
+ struct Point
+ : Base()
+ ;
+
+ interface Base{}
+ """;
+
+ CreateCompilation(src1, parseOptions: TestOptions.Regular11, options: TestOptions.ReleaseDll).VerifyDiagnostics(
+ // (2,7): error CS8861: Unexpected argument list.
+ // : Base()
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(2, 7),
+ // (3,1): error CS9058: Feature 'primary constructors' is not available in C# 11.0. Please use language version 12.0 or greater.
+ // ;
+ Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion11, ";").WithArguments("primary constructors", "12.0").WithLocation(3, 1));
+
+ CreateCompilation(src1, parseOptions: TestOptions.Regular12, options: TestOptions.ReleaseDll).VerifyDiagnostics(
+ // (2,7): error CS8861: Unexpected argument list.
+ // : Base()
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(2, 7));
+
+ CreateCompilation(src1, options: TestOptions.ReleaseDll).VerifyDiagnostics(
+ // (2,7): error CS8861: Unexpected argument list.
+ // : Base()
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "()").WithLocation(2, 7));
}
[Theory]
@@ -1355,9 +1485,9 @@ class C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (13,15): error CS8861: Unexpected argument list.
+ // (13,15): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// class C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(13, 15)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(13, 15)
);
var tree = comp.SyntaxTrees.First();
@@ -1401,9 +1531,9 @@ partial class C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (17,23): error CS8861: Unexpected argument list.
+ // (17,23): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial class C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(17, 23)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(17, 23)
);
var tree = comp.SyntaxTrees.First();
@@ -1454,12 +1584,12 @@ partial class C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (13,23): error CS8861: Unexpected argument list.
+ // (13,23): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial class C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(13, 23),
- // (17,23): error CS8861: Unexpected argument list.
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(13, 23),
+ // (17,23): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial class C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(17, 23)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(17, 23)
);
var tree = comp.SyntaxTrees.First();
@@ -1516,9 +1646,9 @@ partial class C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (17,23): error CS8861: Unexpected argument list.
+ // (17,23): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial class C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(17, 23)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(17, 23)
);
var tree = comp.SyntaxTrees.First();
@@ -1605,9 +1735,9 @@ partial class C(int X, int Y) : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (13,23): error CS8861: Unexpected argument list.
+ // (13,23): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial class C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(13, 23)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(13, 23)
);
var tree = comp.SyntaxTrees.First();
@@ -1804,9 +1934,9 @@ class C : Base(X)
// (11,7): error CS7036: There is no argument given that corresponds to the required parameter 'X' of 'Base.Base(int)'
// class C : Base(X)
Diagnostic(ErrorCode.ERR_NoCorrespondingArgument, "C").WithArguments("X", "Base.Base(int)").WithLocation(11, 7),
- // (11,15): error CS8861: Unexpected argument list.
+ // (11,15): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// class C : Base(X)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X)").WithLocation(11, 15)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X)").WithLocation(11, 15)
);
var tree = comp.SyntaxTrees.First();
@@ -2283,9 +2413,9 @@ interface I {}
var comp = CreateCompilation(src);
comp.VerifyDiagnostics(
- // (11,15): error CS8861: Unexpected argument list.
+ // (11,15): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// class C : Base(GetInt(X, out var xx) + xx, Y), I
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(GetInt(X, out var xx) + xx, Y)").WithLocation(11, 15),
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(GetInt(X, out var xx) + xx, Y)").WithLocation(11, 15),
// (13,30): error CS1729: 'Base' does not contain a constructor that takes 4 arguments
// C(int X, int Y, int Z) : base(X, Y, Z, 1) { return; }
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "base").WithArguments("Base", "4").WithLocation(13, 30)
diff --git a/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs b/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs
index f704ed0086a7e..8c6933b4e2f51 100644
--- a/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs
+++ b/src/Compilers/CSharp/Test/Emit3/Semantics/RecordTests.cs
@@ -21533,9 +21533,9 @@ record C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (13,16): error CS8861: Unexpected argument list.
+ // (13,16): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// record C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(13, 16)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(13, 16)
);
var tree = comp.SyntaxTrees.First();
@@ -21579,9 +21579,9 @@ partial record C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (17,24): error CS8861: Unexpected argument list.
+ // (17,24): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial record C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(17, 24)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(17, 24)
);
var tree = comp.SyntaxTrees.First();
@@ -21632,12 +21632,12 @@ partial record C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (13,24): error CS8861: Unexpected argument list.
+ // (13,24): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial record C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(13, 24),
- // (17,24): error CS8861: Unexpected argument list.
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(13, 24),
+ // (17,24): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial record C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(17, 24)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(17, 24)
);
var tree = comp.SyntaxTrees.First();
@@ -21694,9 +21694,9 @@ partial record C : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (17,24): error CS8861: Unexpected argument list.
+ // (17,24): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial record C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(17, 24)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(17, 24)
);
var tree = comp.SyntaxTrees.First();
@@ -21783,9 +21783,9 @@ partial record C(int X, int Y) : Base(X, Y)
var comp = CreateCompilation(src);
comp.VerifyEmitDiagnostics(
- // (13,24): error CS8861: Unexpected argument list.
+ // (13,24): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// partial record C : Base(X, Y)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X, Y)").WithLocation(13, 24)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X, Y)").WithLocation(13, 24)
);
var tree = comp.SyntaxTrees.First();
@@ -21982,9 +21982,9 @@ record C : Base(X)
// (11,8): error CS1729: 'Base' does not contain a constructor that takes 0 arguments
// record C : Base(X)
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "C").WithArguments("Base", "0").WithLocation(11, 8),
- // (11,16): error CS8861: Unexpected argument list.
+ // (11,16): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// record C : Base(X)
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(X)").WithLocation(11, 16)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(X)").WithLocation(11, 16)
);
var tree = comp.SyntaxTrees.First();
@@ -22499,9 +22499,9 @@ interface I {}
var comp = CreateCompilation(src);
comp.VerifyDiagnostics(
- // (11,16): error CS8861: Unexpected argument list.
+ // (11,16): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
// record C : Base(GetInt(X, out var xx) + xx, Y), I
- Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(GetInt(X, out var xx) + xx, Y)").WithLocation(11, 16),
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(GetInt(X, out var xx) + xx, Y)").WithLocation(11, 16),
// (13,30): error CS1729: 'Base' does not contain a constructor that takes 4 arguments
// C(int X, int Y, int Z) : base(X, Y, Z, 1) { return; }
Diagnostic(ErrorCode.ERR_BadCtorArgCount, "base").WithArguments("Base", "4").WithLocation(13, 30)
@@ -30253,6 +30253,116 @@ record R2 : I(0)
);
}
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48243")]
+ public void RecordInheritanceWithoutParameterList()
+ {
+ var src = """
+ record R1(int P1);
+ record R2 : R1(1);
+ """;
+ var comp = CreateCompilation(src);
+ comp.VerifyEmitDiagnostics(
+ // (2,8): error CS1729: 'R1' does not contain a constructor that takes 0 arguments
+ // record R2 : R1(1);
+ Diagnostic(ErrorCode.ERR_BadCtorArgCount, "R2").WithArguments("R1", "0").WithLocation(2, 8),
+ // (2,15): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
+ // record R2 : R1(1);
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(1)").WithLocation(2, 15));
+ }
+
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48243")]
+ public void RecordClassInheritanceWithoutParameterList()
+ {
+ var src = """
+ record class R1(int P1);
+ record class R2 : R1(42);
+ """;
+ var comp = CreateCompilation(src);
+ comp.VerifyEmitDiagnostics(
+ // (2,14): error CS1729: 'R1' does not contain a constructor that takes 0 arguments
+ // record class R2 : R1(42);
+ Diagnostic(ErrorCode.ERR_BadCtorArgCount, "R2").WithArguments("R1", "0").WithLocation(2, 14),
+ // (2,21): error CS9339: Cannot pass arguments to the base type without a parameter list on the type declaration.
+ // record class R2 : R1(42);
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentListInBaseTypeWithoutParameterList, "(42)").WithLocation(2, 21));
+ }
+
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48243")]
+ public void RecordInheritanceWithEmptyParameterListIsValid()
+ {
+ var src = """
+ record R1(int P1);
+ record R2() : R1(1);
+
+ class Program
+ {
+ static void Main()
+ {
+ var r = new R2();
+ System.Console.WriteLine(r.P1);
+ }
+ }
+ """;
+ CompileAndVerify(src, expectedOutput: "1").VerifyDiagnostics();
+ }
+
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48243")]
+ public void StructWithArgumentListInBaseType()
+ {
+ var src = """
+ interface I
+ {
+ }
+
+ struct S : I(0)
+ {
+ }
+ """;
+ var comp = CreateCompilation(src);
+ comp.VerifyEmitDiagnostics(
+ // (5,13): error CS8861: Unexpected argument list.
+ // struct S : I(0)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(0)").WithLocation(5, 13));
+ }
+
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48243")]
+ public void RecordStructWithArgumentListInBaseType()
+ {
+ var src = """
+ interface I
+ {
+ }
+
+ record struct S : I(0)
+ {
+ }
+ """;
+ var comp = CreateCompilation(src);
+ comp.VerifyEmitDiagnostics(
+ // (5,20): error CS8861: Unexpected argument list.
+ // record struct S : I(0)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(0)").WithLocation(5, 20));
+ }
+
+ [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/48243")]
+ public void RecordWithArgumentListToInterface()
+ {
+ var src = """
+ interface I
+ {
+ }
+
+ record R : I(0)
+ {
+ }
+ """;
+ var comp = CreateCompilation(src);
+ comp.VerifyEmitDiagnostics(
+ // (5,13): error CS8861: Unexpected argument list.
+ // record R : I(0)
+ Diagnostic(ErrorCode.ERR_UnexpectedArgumentList, "(0)").WithLocation(5, 13));
+ }
+
[Theory]
[WorkItem(44902, "https://github.com/dotnet/roslyn/issues/44902")]
[CombinatorialData]