Skip to content

Commit

Permalink
Fixes:dotnet#20226
Browse files Browse the repository at this point in the history
  • Loading branch information
VSadov committed Jun 15, 2017
1 parent ae941fc commit 2faad6f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,9 @@ If such a class is used as a base class and if the deriving class defines a dest
</data>
<data name="ERR_StaticClassInterfaceImpl" xml:space="preserve">
<value>'{0}': static classes cannot implement interfaces</value>
</data>
<data name="ERR_RefStructInterfaceImpl" xml:space="preserve">
<value>'{0}': ref structs cannot implement interfaces</value>
</data>
<data name="ERR_OperatorInStaticClass" xml:space="preserve">
<value>'{0}': static classes cannot contain user-defined operators</value>
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,5 +1513,6 @@ internal enum ErrorCode
ERR_FieldsInRoStruct = 8514,
ERR_AutoPropsInRoStruct = 8515,
ERR_FieldlikeEventsInRoStruct = 8516,
ERR_RefStructInterfaceImpl = 8517,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ private Tuple<NamedTypeSymbol, ImmutableArray<NamedTypeSymbol>> MakeOneDeclaredB
diagnostics.Add(ErrorCode.ERR_StaticClassInterfaceImpl, location, this, baseType);
}

if (this.IsByRefLikeType)
{
// '{0}': static classes cannot implement interfaces
diagnostics.Add(ErrorCode.ERR_RefStructInterfaceImpl, location, this, baseType);
}

if (baseType.ContainsDynamic())
{
diagnostics.Add(ErrorCode.ERR_DeriveFromConstructedDynamic, location, this, baseType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,43 @@ public struct S2
);
}

[WorkItem(20226, "https://github.com/dotnet/roslyn/issues/20226")]
[Fact]
public void InterfaceImpl()
{
var text = @"
using System;
public class Program
{
static void Main(string[] args)
{
using (new S1())
{
}
}
public ref struct S1 : IDisposable
{
public void Dispose() { }
}
}
";

CSharpCompilation comp = CreateCompilationWithMscorlibAndSpan(text);

comp.VerifyDiagnostics(
// (14,28): error CS8517: 'Program.S1': ref structs cannot implement interfaces
// public ref struct S1 : IDisposable
Diagnostic(ErrorCode.ERR_RefStructInterfaceImpl, "IDisposable").WithArguments("Program.S1", "System.IDisposable").WithLocation(14, 28),
// (8,16): error CS1674: 'Program.S1': type used in a using statement must be implicitly convertible to 'System.IDisposable'
// using (new S1())
Diagnostic(ErrorCode.ERR_NoConvToIDisp, "new S1()").WithArguments("Program.S1").WithLocation(8, 16)
);
}


[Fact]
public void Properties()
{
Expand Down

0 comments on commit 2faad6f

Please sign in to comment.