From 4af3f9283bcb99f9fe796f0ff3719b487c24047e Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Wed, 5 Apr 2017 20:26:20 -0700 Subject: [PATCH] Clarify diagnostic for dropped tuple names (#18454) --- .../Portable/CSharpResources.Designer.cs | 4 +- .../CSharp/Portable/CSharpResources.resx | 4 +- .../Test/Emit/CodeGen/CodeGenTupleTest.cs | 4 +- .../Portable/VBResources.Designer.vb | 4 +- .../VisualBasic/Portable/VBResources.resx | 4 +- .../Test/Emit/CodeGen/CodeGenTuples.vb | 69 ++++++++++--------- 6 files changed, 45 insertions(+), 44 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs index 048d24d8b4074..5ced718598a21 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs +++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs @@ -13661,7 +13661,7 @@ internal static string WRN_TooManyLinesForDebugger_Title { } /// - /// Looks up a localized string similar to The tuple element name '{0}' is ignored because a different name is specified by the target type '{1}'.. + /// Looks up a localized string similar to The tuple element name '{0}' is ignored because a different name or no name is specified by the target type '{1}'.. /// internal static string WRN_TupleLiteralNameMismatch { get { @@ -13670,7 +13670,7 @@ internal static string WRN_TupleLiteralNameMismatch { } /// - /// 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.. /// internal static string WRN_TupleLiteralNameMismatch_Title { get { diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index b92caac49a273..9465543e1b591 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -4928,10 +4928,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The type must be 'var'. - The tuple element name '{0}' is ignored because a different name is specified by the target type '{1}'. + The tuple element name '{0}' is ignored because a different name or no name is specified by the target type '{1}'. - The tuple element name is ignored because a different name is specified by the assignment target. + The tuple element name is ignored because a different name or no name is specified by the assignment target. Predefined type '{0}' must be a struct. diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index 52e573a6b45d4..2bd11938610a5 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -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 diff --git a/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb b/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb index 11ad746856e2e..00dedab5397e3 100644 --- a/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb +++ b/src/Compilers/VisualBasic/Portable/VBResources.Designer.vb @@ -14773,7 +14773,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End Property ''' - ''' Looks up a localized string similar to The tuple element name '{0}' is ignored because a different name is specified by the target type '{1}'.. + ''' Looks up a localized string similar to The tuple element name '{0}' is ignored because a different name or no name is specified by the target type '{1}'.. ''' Friend ReadOnly Property WRN_TupleLiteralNameMismatch() As String Get @@ -14782,7 +14782,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End Property ''' - ''' 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.. ''' Friend ReadOnly Property WRN_TupleLiteralNameMismatch_Title() As String Get diff --git a/src/Compilers/VisualBasic/Portable/VBResources.resx b/src/Compilers/VisualBasic/Portable/VBResources.resx index ba8f8bb0fd788..3d01fad784b43 100644 --- a/src/Compilers/VisualBasic/Portable/VBResources.resx +++ b/src/Compilers/VisualBasic/Portable/VBResources.resx @@ -5426,10 +5426,10 @@ Tuple element names must be unique. - The tuple element name '{0}' is ignored because a different name is specified by the target type '{1}'. + The tuple element name '{0}' is ignored because a different name or no name is specified by the target type '{1}'. - The tuple element name is ignored because a different name is specified by the assignment target. + The tuple element name is ignored because a different name or no name is specified by the assignment target. Tuple element name '{0}' is only allowed at position {1}. diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb index e88b9998af2a1..df77ec168f259 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb @@ -10447,22 +10447,22 @@ additionalRefs:=s_valueTupleRefs) comp.AssertTheseDiagnostics( -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)) ~~~~~~~ ) @@ -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)) ~~~~~~~ ) @@ -11334,10 +11334,10 @@ End Class comp.AssertTheseDiagnostics( -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( -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)) ~~~~ ) @@ -17508,7 +17508,7 @@ End Class comp.AssertTheseDiagnostics( -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, ) ~~~~~ ) @@ -17566,16 +17566,16 @@ End Class comp.AssertTheseDiagnostics( -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)) ~~~~ ) @@ -17610,7 +17610,7 @@ End Class comp.AssertTheseDiagnostics( -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)) ~~~~ ) @@ -17655,15 +17655,16 @@ End Class comp.AssertTheseDiagnostics( -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) ~~~~ + ) Dim tree = comp.SyntaxTrees(0) @@ -17868,10 +17869,10 @@ End Class comp.AssertTheseDiagnostics( -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) ~~~~~~~~~~ ) @@ -17902,10 +17903,10 @@ End Class comp.AssertTheseDiagnostics( -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)) ~~~~ ) @@ -17961,13 +17962,13 @@ End Class comp.AssertTheseDiagnostics( -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))) ~~~~~~~~~~~~~~~~~ )