提交 d4b0556e 编写于 作者: L lorcanmooney

Disallow sealed in structs

上级 701404c7
......@@ -853,6 +853,11 @@ private void CheckModifiers(Location location, DiagnosticBag diagnostics)
// '{0}' cannot be sealed because it is not an override
diagnostics.Add(ErrorCode.ERR_SealedNonOverride, location, this);
}
else if (IsSealed && ContainingType.TypeKind == TypeKind.Struct)
{
// The modifier '{0}' is not valid for this item
diagnostics.Add(ErrorCode.ERR_BadMemberFlag, location, SyntaxFacts.GetText(SyntaxKind.SealedKeyword));
}
else if (!ContainingType.IsInterfaceType() && _lazyReturnType.IsStatic)
{
// '{0}': static types cannot be used as return types
......
......@@ -1688,6 +1688,7 @@ struct Foo
public virtual int this[int x] { get { return 1;} set {;} }
// use long for to prevent signature clash
public abstract int this[long x] { get; set; }
public sealed override string ToString() => null;
}
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
......@@ -1714,7 +1715,10 @@ struct Foo
Diagnostic(ErrorCode.ERR_BadMemberFlag, "Bar5").WithArguments("abstract").WithLocation(8, 47),
// (9,46): error CS0106: The modifier 'virtual' is not valid for this item
// public virtual event System.EventHandler Bar6;
Diagnostic(ErrorCode.ERR_BadMemberFlag, "Bar6").WithArguments("virtual").WithLocation(9, 46));
Diagnostic(ErrorCode.ERR_BadMemberFlag, "Bar6").WithArguments("virtual").WithLocation(9, 46),
// (15,35): error CS0106: The modifier 'sealed' is not valid for this item
// public sealed override string ToString() => null;
Diagnostic(ErrorCode.ERR_BadMemberFlag, "ToString").WithArguments("sealed").WithLocation(15, 35));
}
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册