未验证 提交 ca2f6ad9 编写于 作者: L Lauren Fay 提交者: GitHub

Parameter Shadowing Error Fix (#26924)

上级 366eaefd
......@@ -14515,6 +14515,24 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to Type parameter &apos;{0}&apos; has the same name as the type parameter from outer method &apos;{1}&apos;.
/// </summary>
internal static string WRN_TypeParameterSameAsOuterMethodTypeParameter {
get {
return ResourceManager.GetString("WRN_TypeParameterSameAsOuterMethodTypeParameter", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Type parameter has the same type as the type parameter from outer method..
/// </summary>
internal static string WRN_TypeParameterSameAsOuterMethodTypeParameter_Title {
get {
return ResourceManager.GetString("WRN_TypeParameterSameAsOuterMethodTypeParameter_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Type parameter &apos;{0}&apos; has the same name as the type parameter from outer type &apos;{1}&apos;.
/// </summary>
......
......@@ -1943,6 +1943,12 @@ If such a class is used as a base class and if the deriving class defines a dest
<data name="WRN_TypeParameterSameAsOuterTypeParameter_Title" xml:space="preserve">
<value>Type parameter has the same name as the type parameter from outer type</value>
</data>
<data name="WRN_TypeParameterSameAsOuterMethodTypeParameter" xml:space="preserve">
<value>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</value>
</data>
<data name="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title" xml:space="preserve">
<value>Type parameter has the same type as the type parameter from outer method.</value>
</data>
<data name="ERR_TypeVariableSameAsParent" xml:space="preserve">
<value>Type parameter '{0}' has the same name as the containing type, or method</value>
</data>
......@@ -5333,4 +5339,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_OutVariableCannotBeByRef" xml:space="preserve">
<value>An out variable cannot be declared as a ref local</value>
</data>
</root>
\ No newline at end of file
</root>
......@@ -1527,7 +1527,6 @@ internal enum ErrorCode
ERR_RefStructInterfaceImpl = 8343,
ERR_BadSpecialByRefIterator = 8344,
ERR_FieldAutoPropCantBeByRefLike = 8345,
ERR_StackAllocConversionNotPossible = 8346,
ERR_EscapeCall = 8347,
......@@ -1577,8 +1576,8 @@ internal enum ErrorCode
ERR_ExprCannotBeFixed = 8385,
ERR_InvalidObjectCreation = 8386,
#endregion diagnostics introduced for C# 7.3
ERR_OutVariableCannotBeByRef = 8387,
WRN_TypeParameterSameAsOuterMethodTypeParameter = 8387,
ERR_OutVariableCannotBeByRef = 8388,
}
// Note: you will need to re-generate compiler code after adding warnings (build\scripts\generate-compiler-code.cmd)
}
......@@ -323,6 +323,7 @@ internal static int GetWarningLevel(ErrorCode code)
case ErrorCode.WRN_Experimental:
case ErrorCode.WRN_AttributesOnBackingFieldsNotAvailable:
case ErrorCode.WRN_TupleBinopLiteralNameMismatch:
case ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter:
return 1;
default:
return 0;
......
......@@ -179,6 +179,7 @@ public static bool IsWarning(ErrorCode code)
case ErrorCode.WRN_FilterIsConstantFalseRedundantTryCatch:
case ErrorCode.WRN_AttributesOnBackingFieldsNotAvailable:
case ErrorCode.WRN_TupleBinopLiteralNameMismatch:
case ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter:
return true;
default:
return false;
......
......@@ -402,8 +402,19 @@ private ImmutableArray<SourceMethodTypeParameterSymbol> MakeTypeParameters(Diagn
var tpEnclosing = ContainingSymbol.FindEnclosingTypeParameter(name);
if ((object)tpEnclosing != null)
{
// Type parameter '{0}' has the same name as the type parameter from outer type '{1}'
diagnostics.Add(ErrorCode.WRN_TypeParameterSameAsOuterTypeParameter, location, name, tpEnclosing.ContainingSymbol);
ErrorCode typeError;
if (tpEnclosing.ContainingSymbol.Kind == SymbolKind.Method)
{
// Type parameter '{0}' has the same name as the type parameter from outer method '{1}'
typeError = ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter;
}
else
{
Debug.Assert(tpEnclosing.ContainingSymbol.Kind == SymbolKind.NamedType);
// Type parameter '{0}' has the same name as the type parameter from outer type '{1}'
typeError = ErrorCode.WRN_TypeParameterSameAsOuterTypeParameter;
}
diagnostics.Add(typeError, location, name, tpEnclosing.ContainingSymbol);
}
var typeParameter = new SourceMethodTypeParameterSymbol(
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">Znaky {0} se na tomto místě nedají použít.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">Zeichen "{0}" können an dieser Stelle nicht verwendet werden.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">El/los carácter/caracteres '{0}' no se puede/n usar en esta ubicación.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">Impossible d'utiliser le(s) caractère(s) '{0}' à cet emplacement.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">Non è possibile usare il carattere o i caratteri '{0}' in questa posizione.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">文字 '{0}' はこの位置では使用できません。</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">{0}' 문자를 이 위치에 사용할 수 없습니다.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">Znaków „{0}” nie można użyć w tej lokalizacji.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">O(s) caractere(s) "{0}" não pode(m) ser usado(s) neste local.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">В этом месте нельзя использовать символы "{0}".</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">{0}' karakterleri bu konumda kullanılamaz.</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">此位置无法使用字符“{0}”。</target>
......
......@@ -387,6 +387,16 @@
<target state="new">SyntaxTree is not part of the compilation, so it cannot be removed</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
<source>Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</source>
<target state="new">Type parameter '{0}' has the same name as the type parameter from outer method '{1}'</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter_Title">
<source>Type parameter has the same type as the type parameter from outer method.</source>
<target state="new">Type parameter has the same type as the type parameter from outer method.</target>
<note />
</trans-unit>
<trans-unit id="XML_InvalidToken">
<source>The character(s) '{0}' cannot be used at this location.</source>
<target state="translated">此位置不可使用字元 '{0}'。</target>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
......@@ -1064,12 +1064,12 @@ int Local2<U>()
// (18,26): error CS0692: Duplicate type parameter 'T'
// int Local<T, T>() => 0;
Diagnostic(ErrorCode.ERR_DuplicateTypeParameter, "T").WithArguments("T").WithLocation(18, 26),
// (25,23): warning CS0693: Type parameter 'T' has the same name as the type parameter from outer type 'C.M2<T>()'
// (25,23): warning CS8387: Type parameter 'T' has the same name as the type parameter from outer method 'C.M2<T>()'
// int Local<T>() => 0;
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterTypeParameter, "T").WithArguments("T", "C.M2<T>()").WithLocation(25, 23),
// (31,28): warning CS0693: Type parameter 'V' has the same name as the type parameter from outer type 'Local1<V>()'
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter, "T").WithArguments("T", "C.M2<T>()").WithLocation(25, 23),
// (31,28): warning CS8387: Type parameter 'V' has the same name as the type parameter from outer method 'Local1<V>()'
// int Local2<V>() => 0;
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterTypeParameter, "V").WithArguments("V", "Local1<V>()").WithLocation(31, 28),
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter, "V").WithArguments("V", "Local1<V>()").WithLocation(31, 28),
// (37,17): error CS0412: 'T': a parameter, local variable, or local function cannot have the same name as a method type parameter
// int T() => 0;
Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "T").WithArguments("T").WithLocation(37, 17),
......@@ -1079,9 +1079,9 @@ int Local2<U>()
// (54,25): error CS0412: 'T': a parameter, local variable, or local function cannot have the same name as a method type parameter
// int T() => 0;
Diagnostic(ErrorCode.ERR_LocalSameNameAsTypeParam, "T").WithArguments("T").WithLocation(54, 25),
// (67,32): warning CS0693: Type parameter 'T' has the same name as the type parameter from outer type 'C.M2<T>()'
// (67,32): warning CS8387: Type parameter 'T' has the same name as the type parameter from outer method 'C.M2<T>()'
// int Local3<T>() => 0;
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterTypeParameter, "T").WithArguments("T", "C.M2<T>()").WithLocation(67, 32));
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter, "T").WithArguments("T", "C.M2<T>()").WithLocation(67, 32));
}
[Fact]
......@@ -1803,9 +1803,9 @@ T Inner<T>()
}
";
VerifyDiagnostics(source,
// (8,21): warning CS0693: Type parameter 'T' has the same name as the type parameter from outer type 'Outer<T>()'
// (8,21): warning CS8387: Type parameter 'T' has the same name as the type parameter from outer method 'Outer<T>()'
// T Inner<T>()
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterTypeParameter, "T").WithArguments("T", "Outer<T>()").WithLocation(8, 21)
Diagnostic(ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter, "T").WithArguments("T", "Outer<T>()").WithLocation(8, 21)
);
}
......
......@@ -244,6 +244,7 @@ public void WarningLevel_2()
case ErrorCode.WRN_Experimental:
case ErrorCode.WRN_AttributesOnBackingFieldsNotAvailable:
case ErrorCode.WRN_TupleBinopLiteralNameMismatch:
case ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter:
Assert.Equal(1, ErrorFacts.GetWarningLevel(errorCode));
break;
case ErrorCode.WRN_MainIgnored:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册