未验证 提交 c5b3bab9 编写于 作者: V Vladimir Sadov 提交者: GitHub

Merge pull request #24679 from VSadov/fix24348

Produce an error when a bridge method must be variadic
......@@ -5578,6 +5578,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos; cannot implement interface member &apos;{1}&apos; in type &apos;{2}&apos; because it has an __arglist parameter..
/// </summary>
internal static string ERR_InterfaceImplementedImplicitlyByVariadic {
get {
return ResourceManager.GetString("ERR_InterfaceImplementedImplicitlyByVariadic", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &apos;{0}&apos;: interface members cannot have a definition.
/// </summary>
......
......@@ -1755,6 +1755,9 @@ If such a class is used as a base class and if the deriving class defines a dest
<data name="ERR_InterfaceImplementedByConditional" xml:space="preserve">
<value>Conditional member '{0}' cannot implement interface member '{1}' in type '{2}'</value>
</data>
<data name="ERR_InterfaceImplementedImplicitlyByVariadic" xml:space="preserve">
<value>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</value>
</data>
<data name="ERR_IllegalRefParam" xml:space="preserve">
<value>ref and out are not valid in this context</value>
</data>
......
......@@ -427,6 +427,7 @@ internal enum ErrorCode
WRN_ExternMethodNoImplementation = 626,
WRN_ProtectedInSealed = 628,
ERR_InterfaceImplementedByConditional = 629,
ERR_InterfaceImplementedImplicitlyByVariadic = 630,
ERR_IllegalRefParam = 631,
ERR_BadArgumentToAttribute = 633,
//ERR_MissingComTypeOrMarshaller = 635,
......
......@@ -141,7 +141,16 @@ private void CheckAbstractClassImplementations(DiagnosticBag diagnostics)
if ((object)synthesizedImplementation != null)
{
synthesizedImplementations.Add(synthesizedImplementation);
if (synthesizedImplementation.IsVararg)
{
diagnostics.Add(
ErrorCode.ERR_InterfaceImplementedImplicitlyByVariadic,
GetImplicitImplementationDiagnosticLocation(interfaceMember, this, implementingMember), implementingMember, interfaceMember, this);
}
else
{
synthesizedImplementations.Add(synthesizedImplementation);
}
}
if (wasImplementingMemberFound && interfaceMemberKind == SymbolKind.Event)
......
......@@ -1213,7 +1213,7 @@ private static void ReportAnyMismatchedConstraints(MethodSymbol interfaceMethod,
}
}
private static Location GetImplicitImplementationDiagnosticLocation(Symbol interfaceMember, TypeSymbol implementingType, Symbol member)
internal static Location GetImplicitImplementationDiagnosticLocation(Symbol interfaceMember, TypeSymbol implementingType, Symbol member)
{
if (member.ContainingType == implementingType)
{
......
......@@ -8595,6 +8595,11 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -8595,6 +8595,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">ref conditional expression</target>
<note />
</trans-unit>
<trans-unit id="ERR_InterfaceImplementedImplicitlyByVariadic">
<source>'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</source>
<target state="new">'{0}' cannot implement interface member '{1}' in type '{2}' because it has an __arglist parameter</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
\ No newline at end of file
......@@ -13292,6 +13292,162 @@ .maxstack 4
");
}
[WorkItem(24348, "https://github.com/dotnet/roslyn/issues/24348")]
[Fact]
public void VarargBridgeSource()
{
var code = @"
public class VarArgs
{
public void Invoke(__arglist)
{
var ai = new System.ArgIterator(__arglist);
System.Console.WriteLine(ai.GetRemainingCount());
}
}
interface IVarArgs
{
void Invoke(__arglist);
}
class MyVarArgs : VarArgs, IVarArgs
{
}
public static class P
{
public static void Main()
{
IVarArgs iv = new MyVarArgs();
iv.Invoke(__arglist(1, 2, 3, 4));
}
}
";
var compilation = CompileAndVerify(code, expectedOutput: "4");
}
[WorkItem(24348, "https://github.com/dotnet/roslyn/issues/24348")]
[Fact]
public void VarargBridgeMeta()
{
var reference = CreateStandardCompilation(@"
public class VarArgs
{
public void Invoke(__arglist)
{
var ai = new System.ArgIterator(__arglist);
System.Console.WriteLine(ai.GetRemainingCount());
}
}");
var code = @"
interface IVarArgs
{
void Invoke(__arglist);
}
class MyVarArgs : VarArgs, IVarArgs
{
}
public static class P
{
public static void Main()
{
IVarArgs iv = new MyVarArgs();
iv.Invoke(__arglist(1, 2, 3, 4));
}
}
";
var comp = CreateStandardCompilation(code, references: new[] { reference.ToMetadataReference() });
comp.VerifyDiagnostics(
// (7,28): error CS0630: 'VarArgs.Invoke(__arglist)' cannot implement interface member 'IVarArgs.Invoke(__arglist)' in type 'MyVarArgs' because it has an __arglist parameter.
// class MyVarArgs : VarArgs, IVarArgs
Diagnostic(ErrorCode.ERR_InterfaceImplementedImplicitlyByVariadic, "IVarArgs").WithArguments("VarArgs.Invoke(__arglist)", "IVarArgs.Invoke(__arglist)", "MyVarArgs").WithLocation(7, 28)
);
comp = CreateStandardCompilation(code, references: new[] { reference.EmitToImageReference() });
comp.VerifyDiagnostics(
// (7,28): error CS0630: 'VarArgs.Invoke(__arglist)' cannot implement interface member 'IVarArgs.Invoke(__arglist)' in type 'MyVarArgs' because it has an __arglist parameter.
// class MyVarArgs : VarArgs, IVarArgs
Diagnostic(ErrorCode.ERR_InterfaceImplementedImplicitlyByVariadic, "IVarArgs").WithArguments("VarArgs.Invoke(__arglist)", "IVarArgs.Invoke(__arglist)", "MyVarArgs").WithLocation(7, 28)
);
}
[WorkItem(24348, "https://github.com/dotnet/roslyn/issues/24348")]
[ClrOnlyFact(ClrOnlyReason.Ilasm)]
public void VarargBridgeSourceModopt()
{
var il = @"
.class interface public auto ansi abstract IVarArgs
{
// Methods
.method public hidebysig newslot abstract virtual
instance vararg int32 modopt(int64) Invoke () cil managed
{
} // end of method IVarArgs::Invoke
} // end of class IVarArgs
";
var reference = CompileIL(il);
var code = @"
public class VarArgs
{
public int Invoke(__arglist) => throw null;
}
class MyVarArgs : VarArgs, IVarArgs
{
}
class MyVarArgs2 : IVarArgs
{
public int Invoke(__arglist) => throw null;
}
class MyVarArgs3 : IVarArgs
{
// this is ok, modifiers are copied
int IVarArgs.Invoke(__arglist) => throw null;
}
public static class P
{
public static void Main()
{
IVarArgs iv = new MyVarArgs3();
iv.Invoke(__arglist(1, 2, 3, 4));
}
}
";
var comp = CreateStandardCompilation(code, references: new[] { reference});
comp.VerifyDiagnostics(
// (15,16): error CS0630: 'MyVarArgs2.Invoke(__arglist)' cannot implement interface member 'IVarArgs.Invoke(__arglist)' in type 'MyVarArgs2' because it has an __arglist parameter
// public int Invoke(__arglist) => throw null;
Diagnostic(ErrorCode.ERR_InterfaceImplementedImplicitlyByVariadic, "Invoke").WithArguments("MyVarArgs2.Invoke(__arglist)", "IVarArgs.Invoke(__arglist)", "MyVarArgs2").WithLocation(15, 16),
// (8,28): error CS0630: 'VarArgs.Invoke(__arglist)' cannot implement interface member 'IVarArgs.Invoke(__arglist)' in type 'MyVarArgs' because it has an __arglist parameter
// class MyVarArgs : VarArgs, IVarArgs
Diagnostic(ErrorCode.ERR_InterfaceImplementedImplicitlyByVariadic, "IVarArgs").WithArguments("VarArgs.Invoke(__arglist)", "IVarArgs.Invoke(__arglist)", "MyVarArgs").WithLocation(8, 28)
);
}
[WorkItem(530067, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530067")]
[Fact]
public void NopAfterCall()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册