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

Allow structures to implement nested interfaces as we do for classes. (#41711)

Fixes #41501.
上级 0898a78e
......@@ -571,12 +571,12 @@ private ImmutableArray<NamedTypeSymbol> MakeAcyclicInterfaces(ConsList<TypeSymbo
}
var declaredInterfaces = GetDeclaredInterfaces(basesBeingResolved: basesBeingResolved);
bool isClass = (typeKind == TypeKind.Class);
bool isInterface = (typeKind == TypeKind.Interface);
ArrayBuilder<NamedTypeSymbol> result = isClass ? null : ArrayBuilder<NamedTypeSymbol>.GetInstance();
ArrayBuilder<NamedTypeSymbol> result = isInterface ? ArrayBuilder<NamedTypeSymbol>.GetInstance() : null;
foreach (var t in declaredInterfaces)
{
if (!isClass)
if (isInterface)
{
if (BaseTypeAnalysis.TypeDependsOn(depends: t, on: this))
{
......@@ -611,7 +611,7 @@ private ImmutableArray<NamedTypeSymbol> MakeAcyclicInterfaces(ConsList<TypeSymbo
}
}
return isClass ? declaredInterfaces : result.ToImmutableAndFree();
return isInterface ? result.ToImmutableAndFree() : declaredInterfaces;
}
private NamedTypeSymbol MakeAcyclicBaseType(DiagnosticBag diagnostics)
......
......@@ -2292,5 +2292,37 @@ public interface I1
Assert.True(i1.IsExplicitDefinitionOfNoPiaLocalType);
}
[Fact]
[WorkItem(41501, "https://github.com/dotnet/roslyn/issues/41501")]
public void ImplementNestedInterface_01()
{
var text = @"
public struct TestStruct : TestStruct.IInnerInterface
{
public interface IInnerInterface
{
}
}
";
var compilation = CreateCompilation(text);
compilation.VerifyDiagnostics();
}
[Fact]
[WorkItem(41501, "https://github.com/dotnet/roslyn/issues/41501")]
public void ImplementNestedInterface_02()
{
var text = @"
public class TestClass : TestClass.IInnerInterface
{
public interface IInnerInterface
{
}
}
";
var compilation = CreateCompilation(text);
compilation.VerifyDiagnostics();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册