提交 0b767d7b 编写于 作者: A Andy Gocke

Adjust tests from comments

上级 3b8cccc3
......@@ -1071,5 +1071,83 @@ .maxstack 2
IL_001b: ret
}");
}
[Fact]
public void DataClassAndStruct()
{
var src = @"
data class C1 { }
data class C2(int X, int Y);
data struct S1 { }
data struct S2(int X, int Y);";
var comp = CreateCompilation(src);
comp.VerifyDiagnostics(
// error CS8805: Program using top-level statements must be an executable.
Diagnostic(ErrorCode.ERR_SimpleProgramNotAnExecutable).WithLocation(1, 1),
// (2,1): error CS0116: A namespace cannot directly contain members such as fields or methods
// data class C1 { }
Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "data").WithLocation(2, 1),
// (3,1): error CS0116: A namespace cannot directly contain members such as fields or methods
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "data").WithLocation(3, 1),
// (3,14): error CS1514: { expected
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_LbraceExpected, "(").WithLocation(3, 14),
// (3,14): error CS1513: } expected
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_RbraceExpected, "(").WithLocation(3, 14),
// (3,14): error CS8803: Top-level statements must precede namespace and type declarations.
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_TopLevelStatementAfterNamespaceOrType, "(int X, int Y);").WithLocation(3, 14),
// (3,14): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_IllegalStatement, "(int X, int Y)").WithLocation(3, 14),
// (3,15): error CS8185: A declaration is not allowed in this context.
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_DeclarationExpressionNotPermitted, "int X").WithLocation(3, 15),
// (3,15): error CS0165: Use of unassigned local variable 'X'
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_UseDefViolation, "int X").WithArguments("X").WithLocation(3, 15),
// (3,22): error CS8185: A declaration is not allowed in this context.
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_DeclarationExpressionNotPermitted, "int Y").WithLocation(3, 22),
// (3,22): error CS0165: Use of unassigned local variable 'Y'
// data class C2(int X, int Y);
Diagnostic(ErrorCode.ERR_UseDefViolation, "int Y").WithArguments("Y").WithLocation(3, 22),
// (4,1): error CS0116: A namespace cannot directly contain members such as fields or methods
// data struct S1 { }
Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "data").WithLocation(4, 1),
// (5,1): error CS0116: A namespace cannot directly contain members such as fields or methods
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_NamespaceUnexpected, "data").WithLocation(5, 1),
// (5,15): error CS1514: { expected
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_LbraceExpected, "(").WithLocation(5, 15),
// (5,15): error CS1513: } expected
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_RbraceExpected, "(").WithLocation(5, 15),
// (5,15): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_IllegalStatement, "(int X, int Y)").WithLocation(5, 15),
// (5,16): error CS8185: A declaration is not allowed in this context.
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_DeclarationExpressionNotPermitted, "int X").WithLocation(5, 16),
// (5,16): error CS0165: Use of unassigned local variable 'X'
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_UseDefViolation, "int X").WithArguments("X").WithLocation(5, 16),
// (5,20): error CS0128: A local variable or function named 'X' is already defined in this scope
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_LocalDuplicate, "X").WithArguments("X").WithLocation(5, 20),
// (5,23): error CS8185: A declaration is not allowed in this context.
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_DeclarationExpressionNotPermitted, "int Y").WithLocation(5, 23),
// (5,23): error CS0165: Use of unassigned local variable 'Y'
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_UseDefViolation, "int Y").WithArguments("Y").WithLocation(5, 23),
// (5,27): error CS0128: A local variable or function named 'Y' is already defined in this scope
// data struct S2(int X, int Y);
Diagnostic(ErrorCode.ERR_LocalDuplicate, "Y").WithArguments("Y").WithLocation(5, 27)
);
}
}
}
......@@ -1314,7 +1314,7 @@ public void WithParsing19()
}
[Fact]
public void InvalidBase()
public void BadParameterListAndBaseListOnClass()
{
var text = @$"
class C(int X, int Y)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册