未验证 提交 a3f2539d 编写于 作者: A AlekseyTs 提交者: GitHub

Add Default Interface Implementation tests for VB (#35957)

Add Default Interface Implementation tests for VB

Related to #35820, #35821, #35823, #35824, #35827, #35834, #35852, #35885, #35911, #35948.
上级 655ada40
......@@ -60,7 +60,7 @@ class Test1 : I2 // This type must implement all members of I1
{
}
```
In metadata, methods representing re-abstraction have all three flags `abstarct`, `virtual`, `sealed` set and do not have `newslot` flag set.
In metadata, methods representing re-abstraction have all three flags `abstract`, `virtual`, `sealed` set and do not have `newslot` flag set.
- Supplying an implementation along with declaration of a property or an indexer and recognizing that implementation as default implementation for them when a type implements the interface.
......
......@@ -39860,6 +39860,94 @@ static void Main()
}
}
[Fact]
public void UnsupportedMemberAccess_04()
{
var source1 =
@"
public interface I1
{
protected interface I2 {}
protected internal interface I3 {}
}
";
var compilation1 = CreateCompilation(source1, options: TestOptions.DebugDll,
parseOptions: TestOptions.Regular,
targetFramework: TargetFramework.NetStandardLatest);
Assert.True(compilation1.Assembly.RuntimeSupportsDefaultInterfaceImplementation);
compilation1.VerifyDiagnostics();
var source3 =
@"
interface Test3 : I1
{
class C
{
static void M1(I1.I2 x)
{
System.Console.WriteLine(""M1"");
}
static void M2(I1.I3 x)
{
System.Console.WriteLine(""M2"");
}
static void Main()
{
M1(null);
M2(null);
}
}
}
";
var source4 =
@"
class Test4 : I1
{
interface Test5 : I1.I2
{
}
interface Test6 : I1.I3
{
}
}
";
foreach (var reference in new[] { compilation1.ToMetadataReference(), compilation1.EmitToImageReference() })
{
var compilation3 = CreateCompilation(source3, options: TestOptions.DebugExe,
targetFramework: TargetFramework.DesktopLatestExtended,
references: new[] { reference },
parseOptions: TestOptions.Regular);
compilation3.VerifyDiagnostics(
// (6,27): error CS8707: Target runtime doesn't support 'protected', 'protected internal', or 'private protected' accessibility for a member of an interface.
// static void M1(I1.I2 x)
Diagnostic(ErrorCode.ERR_RuntimeDoesNotSupportProtectedAccessForInterfaceMember, "I2").WithLocation(6, 27),
// (11,27): error CS8707: Target runtime doesn't support 'protected', 'protected internal', or 'private protected' accessibility for a member of an interface.
// static void M2(I1.I3 x)
Diagnostic(ErrorCode.ERR_RuntimeDoesNotSupportProtectedAccessForInterfaceMember, "I3").WithLocation(11, 27)
);
var compilation4 = CreateCompilation(source4, options: TestOptions.DebugDll,
targetFramework: TargetFramework.DesktopLatestExtended,
references: new[] { reference },
parseOptions: TestOptions.Regular);
compilation4.VerifyDiagnostics(
// (4,26): error CS8707: Target runtime doesn't support 'protected', 'protected internal', or 'private protected' accessibility for a member of an interface.
// interface Test5 : I1.I2
Diagnostic(ErrorCode.ERR_RuntimeDoesNotSupportProtectedAccessForInterfaceMember, "I2").WithLocation(4, 26),
// (8,26): error CS8707: Target runtime doesn't support 'protected', 'protected internal', or 'private protected' accessibility for a member of an interface.
// interface Test6 : I1.I3
Diagnostic(ErrorCode.ERR_RuntimeDoesNotSupportProtectedAccessForInterfaceMember, "I3").WithLocation(8, 26)
);
}
}
[Fact]
public void EntryPoint_01()
{
......@@ -44008,6 +44096,62 @@ public interface ITest33
}
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/35911")]
[WorkItem(35911, "https://github.com/dotnet/roslyn/issues/35911")]
public void NoPia_10()
{
var attributes = CreateCompilation(NoPiaAttributes, options: TestOptions.ReleaseDll, targetFramework: TargetFramework.NetStandardLatest);
var attributesRef = attributes.EmitToImageReference();
string pia = @"
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
[assembly: PrimaryInteropAssemblyAttribute(1,1)]
[assembly: Guid(""f9c2d51d-4f44-45f0-9eda-c9d599b58257"")]
[ComImport()]
[Guid(""f9c2d51d-4f44-45f0-9eda-c9d599b58279"")]
public interface ITest33
{
void M1();
}
[ComImport()]
[Guid(""f9c2d51d-4f44-45f0-9eda-c9d599b58280"")]
public interface ITest44 : ITest33
{
abstract void ITest33.M1();
}
";
var piaCompilation = CreateCompilation(pia, options: TestOptions.ReleaseDll, references: new[] { attributesRef }, targetFramework: TargetFramework.NetStandardLatest);
CompileAndVerify(piaCompilation, verify: VerifyOnMonoOrCoreClr);
string consumer = @"
class UsePia
{
public static void Main(ITest44 x)
{
x.M1();
}
}
";
foreach (var reference in new[] { piaCompilation.ToMetadataReference(embedInteropTypes: true), piaCompilation.EmitToImageReference(embedInteropTypes: true) })
{
var compilation1 = CreateCompilation(consumer, options: TestOptions.ReleaseDll, references: new[] { reference, attributesRef }, targetFramework: TargetFramework.NetStandardLatest);
compilation1.VerifyEmitDiagnostics(
// (4,29): error CS8711: Type 'ITest44' cannot be embedded because it has a non-abstract member. Consider setting the 'Embed Interop Types' property to false.
// public static void Main(ITest44 x)
Diagnostic(ErrorCode.ERR_DefaultInterfaceImplementationInNoPIAType, "ITest44").WithArguments("ITest44").WithLocation(4, 29)
);
}
}
[Fact]
public void LambdaCaching_01()
{
......@@ -3,7 +3,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>$(RoslynPortableTargetFrameworks)</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp3.0</TargetFrameworks>
<RootNamespace></RootNamespace>
<!-- A zillion test failures + crash. See https://github.com/mono/mono/issues/10756. -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册