提交 4af3f928 编写于 作者: J Julien Couvreur 提交者: GitHub

Clarify diagnostic for dropped tuple names (#18454)

上级 3c43a682
......@@ -13661,7 +13661,7 @@ internal class CSharpResources {
}
/// <summary>
/// Looks up a localized string similar to The tuple element name &apos;{0}&apos; is ignored because a different name is specified by the target type &apos;{1}&apos;..
/// Looks up a localized string similar to The tuple element name &apos;{0}&apos; is ignored because a different name or no name is specified by the target type &apos;{1}&apos;..
/// </summary>
internal static string WRN_TupleLiteralNameMismatch {
get {
......@@ -13670,7 +13670,7 @@ internal class CSharpResources {
}
/// <summary>
/// Looks up a localized string similar to The tuple element name is ignored because a different name is specified by the assignment target..
/// Looks up a localized string similar to The tuple element name is ignored because a different name or no name is specified by the assignment target..
/// </summary>
internal static string WRN_TupleLiteralNameMismatch_Title {
get {
......
......@@ -4928,10 +4928,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>The type must be 'var'.</value>
</data>
<data name="WRN_TupleLiteralNameMismatch" xml:space="preserve">
<value>The tuple element name '{0}' is ignored because a different name is specified by the target type '{1}'.</value>
<value>The tuple element name '{0}' is ignored because a different name or no name is specified by the target type '{1}'.</value>
</data>
<data name="WRN_TupleLiteralNameMismatch_Title" xml:space="preserve">
<value>The tuple element name is ignored because a different name is specified by the assignment target.</value>
<value>The tuple element name is ignored because a different name or no name is specified by the assignment target.</value>
</data>
<data name="ERR_PredefinedValueTupleTypeMustBeStruct" xml:space="preserve">
<value>Predefined type '{0}' must be a struct.</value>
......
......@@ -17236,10 +17236,10 @@ public void M()
";
var comp = CreateCompilationWithMscorlib(source, references: s_valueTupleRefs);
comp.VerifyDiagnostics(
// (6,31): warning CS8123: The tuple element name 'b' is ignored because a different name is specified by the target type '(int a, int)'.
// (6,31): warning CS8123: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(int a, int)'.
// (int a, int) x1 = (1, b: 2);
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "b: 2").WithArguments("b", "(int a, int)").WithLocation(6, 31),
// (7,34): warning CS8123: The tuple element name 'b' is ignored because a different name is specified by the target type '(int a, string)'.
// (7,34): warning CS8123: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(int a, string)'.
// (int a, string) x2 = (1, b: null);
Diagnostic(ErrorCode.WRN_TupleLiteralNameMismatch, "b: null").WithArguments("b", "(int a, string)").WithLocation(7, 34),
// (6,22): warning CS0219: The variable 'x1' is assigned but its value is never used
......
......@@ -14773,7 +14773,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Property
'''<summary>
''' Looks up a localized string similar to The tuple element name &apos;{0}&apos; is ignored because a different name is specified by the target type &apos;{1}&apos;..
''' Looks up a localized string similar to The tuple element name &apos;{0}&apos; is ignored because a different name or no name is specified by the target type &apos;{1}&apos;..
'''</summary>
Friend ReadOnly Property WRN_TupleLiteralNameMismatch() As String
Get
......@@ -14782,7 +14782,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Property
'''<summary>
''' Looks up a localized string similar to The tuple element name is ignored because a different name is specified by the assignment target..
''' Looks up a localized string similar to The tuple element name is ignored because a different name or no name is specified by the assignment target..
'''</summary>
Friend ReadOnly Property WRN_TupleLiteralNameMismatch_Title() As String
Get
......
......@@ -5426,10 +5426,10 @@
<value>Tuple element names must be unique.</value>
</data>
<data name="WRN_TupleLiteralNameMismatch" xml:space="preserve">
<value>The tuple element name '{0}' is ignored because a different name is specified by the target type '{1}'.</value>
<value>The tuple element name '{0}' is ignored because a different name or no name is specified by the target type '{1}'.</value>
</data>
<data name="WRN_TupleLiteralNameMismatch_Title" xml:space="preserve">
<value>The tuple element name is ignored because a different name is specified by the assignment target.</value>
<value>The tuple element name is ignored because a different name or no name is specified by the assignment target.</value>
</data>
<data name="ERR_TupleReservedElementName" xml:space="preserve">
<value>Tuple element name '{0}' is only allowed at position {1}.</value>
......
......@@ -10447,22 +10447,22 @@ additionalRefs:=s_valueTupleRefs)
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'e' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'e' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x1 As (a As Integer, b As Integer) = DirectCast((e:=1, f:=2), (c As Long, d As Long))
~~~~
BC41009: The tuple element name 'f' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'f' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x1 As (a As Integer, b As Integer) = DirectCast((e:=1, f:=2), (c As Long, d As Long))
~~~~
BC41009: The tuple element name 'e' is ignored because a different name is specified by the target type '(c As Integer, d As Integer)'.
BC41009: The tuple element name 'e' is ignored because a different name or no name is specified by the target type '(c As Integer, d As Integer)'.
Dim x2 As (a As Short, b As Short) = DirectCast((e:=1, f:=2), (c As Integer, d As Integer))
~~~~
BC41009: The tuple element name 'f' is ignored because a different name is specified by the target type '(c As Integer, d As Integer)'.
BC41009: The tuple element name 'f' is ignored because a different name or no name is specified by the target type '(c As Integer, d As Integer)'.
Dim x2 As (a As Short, b As Short) = DirectCast((e:=1, f:=2), (c As Integer, d As Integer))
~~~~
BC41009: The tuple element name 'e' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'e' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x3 As (a As Integer, b As Integer) = DirectCast((e:=1, f:="qq"), (c As Long, d As Long))
~~~~
BC41009: The tuple element name 'f' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'f' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x3 As (a As Integer, b As Integer) = DirectCast((e:=1, f:="qq"), (c As Long, d As Long))
~~~~~~~
</errors>)
......@@ -10493,28 +10493,28 @@ additionalRefs:=s_valueTupleRefs)
BC30512: Option Strict On disallows implicit conversions from '(c As Long, d As Long)' to '(a As Integer, b As Integer)'.
Dim x1 As (a As Integer, b As Integer) = DirectCast((e:=1, f:=2), (c As Long, d As Long))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC41009: The tuple element name 'e' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'e' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x1 As (a As Integer, b As Integer) = DirectCast((e:=1, f:=2), (c As Long, d As Long))
~~~~
BC41009: The tuple element name 'f' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'f' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x1 As (a As Integer, b As Integer) = DirectCast((e:=1, f:=2), (c As Long, d As Long))
~~~~
BC30512: Option Strict On disallows implicit conversions from '(c As Integer, d As Integer)' to '(a As Short, b As Short)'.
Dim x2 As (a As Short, b As Short) = DirectCast((e:=1, f:=2), (c As Integer, d As Integer))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC41009: The tuple element name 'e' is ignored because a different name is specified by the target type '(c As Integer, d As Integer)'.
BC41009: The tuple element name 'e' is ignored because a different name or no name is specified by the target type '(c As Integer, d As Integer)'.
Dim x2 As (a As Short, b As Short) = DirectCast((e:=1, f:=2), (c As Integer, d As Integer))
~~~~
BC41009: The tuple element name 'f' is ignored because a different name is specified by the target type '(c As Integer, d As Integer)'.
BC41009: The tuple element name 'f' is ignored because a different name or no name is specified by the target type '(c As Integer, d As Integer)'.
Dim x2 As (a As Short, b As Short) = DirectCast((e:=1, f:=2), (c As Integer, d As Integer))
~~~~
BC30512: Option Strict On disallows implicit conversions from '(c As Long, d As Long)' to '(a As Integer, b As Integer)'.
Dim x3 As (a As Integer, b As Integer) = DirectCast((e:=1, f:="qq"), (c As Long, d As Long))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BC41009: The tuple element name 'e' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'e' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x3 As (a As Integer, b As Integer) = DirectCast((e:=1, f:="qq"), (c As Long, d As Long))
~~~~
BC41009: The tuple element name 'f' is ignored because a different name is specified by the target type '(c As Long, d As Long)'.
BC41009: The tuple element name 'f' is ignored because a different name or no name is specified by the target type '(c As Long, d As Long)'.
Dim x3 As (a As Integer, b As Integer) = DirectCast((e:=1, f:="qq"), (c As Long, d As Long))
~~~~~~~
</errors>)
......@@ -11334,10 +11334,10 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'e' is ignored because a different name is specified by the target type '(a As Short, b As String)'.
BC41009: The tuple element name 'e' is ignored because a different name or no name is specified by the target type '(a As Short, b As String)'.
Dim x As (a As Short, b As String) = (e:=1, f:=New C1("qq"))
~~~~
BC41009: The tuple element name 'f' is ignored because a different name is specified by the target type '(a As Short, b As String)'.
BC41009: The tuple element name 'f' is ignored because a different name or no name is specified by the target type '(a As Short, b As String)'.
Dim x As (a As Short, b As String) = (e:=1, f:=New C1("qq"))
~~~~~~~~~~~~~~~
BC30512: Option Strict On disallows implicit conversions from 'C.C1' to 'String'.
......@@ -17449,10 +17449,10 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'b' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Dim x1 = If(flag, (a:=1, b:=2), (a:=1, c:=3))
~~~~
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Dim x1 = If(flag, (a:=1, b:=2), (a:=1, c:=3))
~~~~
</errors>)
......@@ -17508,7 +17508,7 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Dim x6 = If(nab, (a:= 1, c:= 3)) ' (a, )
~~~~~
</errors>)
......@@ -17566,16 +17566,16 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'a' is ignored because a different name is specified by the target type '(Integer, Integer)'.
BC41009: The tuple element name 'a' is ignored because a different name or no name is specified by the target type '(Integer, Integer)'.
Dim x1 = If(flag, (a:=1, b:=2), (1, 3))
~~~~
BC41009: The tuple element name 'b' is ignored because a different name is specified by the target type '(Integer, Integer)'.
BC41009: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(Integer, Integer)'.
Dim x1 = If(flag, (a:=1, b:=2), (1, 3))
~~~~
BC41009: The tuple element name 'a' is ignored because a different name is specified by the target type '(Integer, Integer)'.
BC41009: The tuple element name 'a' is ignored because a different name or no name is specified by the target type '(Integer, Integer)'.
Dim x2 = If(flag, (1, 2), (a:=1, b:=3))
~~~~
BC41009: The tuple element name 'b' is ignored because a different name is specified by the target type '(Integer, Integer)'.
BC41009: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(Integer, Integer)'.
Dim x2 = If(flag, (1, 2), (a:=1, b:=3))
~~~~
</errors>)
......@@ -17610,7 +17610,7 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(a As Integer, b As Long)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(a As Integer, b As Long)'.
Dim x1 = If(flag, (a:=1, b:=CType(2, Long)), (a:=CType(1, Byte), c:=3))
~~~~
</errors>)
......@@ -17655,15 +17655,16 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'b' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Return (a:=1, b:=2)
~~~~
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Return (a:=1, c:=3)
~~~~
BC41009: The tuple element name 'd' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'd' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Return (a:=1, d:=4)
~~~~
</errors>)
Dim tree = comp.SyntaxTrees(0)
......@@ -17868,10 +17869,10 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'b' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Dim x1 As (a As Integer, Integer) = (1, b:=2)
~~~~
BC41009: The tuple element name 'b' is ignored because a different name is specified by the target type '(a As Integer, String)'.
BC41009: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(a As Integer, String)'.
Dim x2 As (a As Integer, String) = (1, b:=Nothing)
~~~~~~~~~~
</errors>)
......@@ -17902,10 +17903,10 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'b' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'b' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Dim t = M2((a:=1, b:=2), (a:=1, c:=3))
~~~~
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(a As Integer, Integer)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(a As Integer, Integer)'.
Dim t = M2((a:=1, b:=2), (a:=1, c:=3))
~~~~
BC30456: 'b' is not a member of '(a As Integer, Integer)'.
......@@ -17914,10 +17915,10 @@ BC30456: 'b' is not a member of '(a As Integer, Integer)'.
BC30456: 'c' is not a member of '(a As Integer, Integer)'.
System.Console.Write(t.c)
~~~
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(Integer, Integer)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(Integer, Integer)'.
M2((1, 2), (c:=1, d:=3))
~~~~
BC41009: The tuple element name 'd' is ignored because a different name is specified by the target type '(Integer, Integer)'.
BC41009: The tuple element name 'd' is ignored because a different name or no name is specified by the target type '(Integer, Integer)'.
M2((1, 2), (c:=1, d:=3))
~~~~
</errors>)
......@@ -17961,13 +17962,13 @@ End Class
comp.AssertTheseDiagnostics(
<errors>
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(a As Integer, b As Integer)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(a As Integer, b As Integer)'.
M2((a:=1, b:=2), (a:=CType(1, Byte), c:=CType(3, Byte)))
~~~~~~~~~~~~~~~~~
BC41009: The tuple element name 'c' is ignored because a different name is specified by the target type '(Long, b As Integer)'.
BC41009: The tuple element name 'c' is ignored because a different name or no name is specified by the target type '(Long, b As Integer)'.
M2((CType(1, Long), b:=2), (c:=1, d:=CType(3, Byte)))
~~~~
BC41009: The tuple element name 'd' is ignored because a different name is specified by the target type '(Long, b As Integer)'.
BC41009: The tuple element name 'd' is ignored because a different name or no name is specified by the target type '(Long, b As Integer)'.
M2((CType(1, Long), b:=2), (c:=1, d:=CType(3, Byte)))
~~~~~~~~~~~~~~~~~
</errors>)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册