提交 fab958dc 编写于 作者: T Tomáš Matoušek

Improve and localize EnC error message (#11381)

上级 2d797bb9
......@@ -3517,6 +3517,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to Cannot update &apos;{0}&apos;; attribute &apos;{1}&apos; is missing..
/// </summary>
internal static string ERR_EncUpdateFailedMissingAttribute {
get {
return ResourceManager.GetString("ERR_EncUpdateFailedMissingAttribute", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to #endif directive expected.
/// </summary>
......
......@@ -3833,6 +3833,9 @@ You should consider suppressing the warning only if you're sure that you don't w
<data name="ERR_FixedLocalInLambda" xml:space="preserve">
<value>Cannot use fixed local '{0}' inside an anonymous method, lambda expression, or query expression</value>
</data>
<data name="ERR_EncUpdateFailedMissingAttribute" xml:space="preserve">
<value>Cannot update '{0}'; attribute '{1}' is missing.</value>
</data>
<data name="ERR_ExpressionTreeContainsNamedArgument" xml:space="preserve">
<value>An expression tree may not contain a named argument specification</value>
</data>
......
......@@ -1174,6 +1174,7 @@ internal enum ErrorCode
// ERR_NameIllegallyOverrides3 = 7040, // Not used anymore due to 'Single Meaning' relaxation changes
ERR_ResourceFileNameNotUnique = 7041,
ERR_DllImportOnGenericMethod = 7042,
ERR_EncUpdateFailedMissingAttribute = 7043,
ERR_ParameterNotValidForType = 7045,
ERR_AttributeParameterRequired1 = 7046,
......
......@@ -95,7 +95,7 @@ public override Diagnostic CreateDiagnostic(int code, Location location, params
return new CSDiagnostic(info, location);
}
public override string ConvertSymbolToString(int errorCode, ISymbol symbol)
public override string GetErrorDisplayString(ISymbol symbol)
{
// show extra info for assembly if possible such as version, public key token etc.
if (symbol.Kind == SymbolKind.Assembly || symbol.Kind == SymbolKind.Namespace)
......@@ -205,6 +205,7 @@ public override void ReportDuplicateMetadataReferenceWeak(DiagnosticBag diagnost
public override int ERR_TooManyUserStrings { get { return (int)ErrorCode.ERR_TooManyUserStrings; } }
public override int ERR_PeWritingFailure { get { return (int)ErrorCode.ERR_PeWritingFailure; } }
public override int ERR_ModuleEmitFailure { get { return (int)ErrorCode.ERR_ModuleEmitFailure; } }
public override int ERR_EncUpdateFailedMissingAttribute { get { return (int)ErrorCode.ERR_EncUpdateFailedMissingAttribute; } }
public override void ReportInvalidAttributeArgument(DiagnosticBag diagnostics, SyntaxNode attributeSyntax, int parameterIndex, AttributeData attribute)
{
......
......@@ -4756,8 +4756,8 @@ public IEnumerable<int> F()
new SemanticEdit(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));
diff1.EmitResult.Diagnostics.Verify(
// error CS7038: Failed to emit module '{0}'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments(compilation0.SourceModule.Name));
// error CS7043: Cannot update 'C.F()'; attribute 'System.Runtime.CompilerServices.IteratorStateMachineAttribute' is missing.
Diagnostic(ErrorCode.ERR_EncUpdateFailedMissingAttribute).WithArguments("C.F()", "System.Runtime.CompilerServices.IteratorStateMachineAttribute"));
}
[Fact, WorkItem(9119, "https://github.com/dotnet/roslyn/issues/9119")]
......@@ -4811,10 +4811,10 @@ public async Task<int> F()
new SemanticEdit(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));
diff1.EmitResult.Diagnostics.Verify(
// error CS7038: Failed to emit module '{0}'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments(compilation0.SourceModule.Name),
// error CS7038: Failed to emit module '{0}'.
Diagnostic(ErrorCode.ERR_ModuleEmitFailure).WithArguments(compilation0.SourceModule.Name));
// error CS7043: Cannot update 'C.F()'; attribute 'System.Runtime.CompilerServices.AsyncStateMachineAttribute' is missing.
Diagnostic(ErrorCode.ERR_EncUpdateFailedMissingAttribute).WithArguments("C.F()", "System.Runtime.CompilerServices.AsyncStateMachineAttribute"),
// error CS7043: Cannot update 'C.F()'; attribute 'System.Runtime.CompilerServices.AsyncStateMachineAttribute' is missing.
Diagnostic(ErrorCode.ERR_EncUpdateFailedMissingAttribute).WithArguments("C.F()", "System.Runtime.CompilerServices.AsyncStateMachineAttribute"));
}
}
}
......@@ -2226,9 +2226,9 @@ public override int GetWarningLevel(int code)
}
}
public override string ConvertSymbolToString(int errorCode, ISymbol symbol)
public override string GetErrorDisplayString(ISymbol symbol)
{
return MessageProvider.Instance.ConvertSymbolToString(errorCode, symbol);
return MessageProvider.Instance.GetErrorDisplayString(symbol);
}
}
......
......@@ -314,6 +314,15 @@ internal class CodeAnalysisResources {
}
}
/// <summary>
/// Looks up a localized string similar to The compilation references multiple assemblies whose versions only differ in auto-generated build and/or revision numbers..
/// </summary>
internal static string CompilationReferencesAssembliesWithDifferentAutoGeneratedVersion {
get {
return ResourceManager.GetString("CompilationReferencesAssembliesWithDifferentAutoGeneratedVersion", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Analyzer Failure.
/// </summary>
......
......@@ -516,4 +516,7 @@
<data name="IOperationFeatureDisabled" xml:space="preserve">
<value>Feature 'IOperation' is disabled.</value>
</data>
<data name="CompilationReferencesAssembliesWithDifferentAutoGeneratedVersion" xml:space="preserve">
<value>The compilation references multiple assemblies whose versions only differ in auto-generated build and/or revision numbers.</value>
</data>
</root>
\ No newline at end of file
......@@ -86,9 +86,9 @@ public Diagnostic CreateDiagnostic(int code, Location location)
public abstract string GetMessagePrefix(string id, DiagnosticSeverity severity, bool isWarningAsError, CultureInfo culture);
/// <summary>
/// convert given symbol to string representation based on given error code
/// Convert given symbol to string representation.
/// </summary>
public abstract string ConvertSymbolToString(int errorCode, ISymbol symbol);
public abstract string GetErrorDisplayString(ISymbol symbol);
/// <summary>
/// Given an error code (like 1234) return the identifier (CS1234 or BC1234).
......@@ -206,6 +206,7 @@ public DiagnosticInfo FilterDiagnosticInfo(DiagnosticInfo diagnosticInfo, Compil
public abstract int ERR_TooManyUserStrings { get; }
public abstract int ERR_PeWritingFailure { get; }
public abstract int ERR_ModuleEmitFailure { get; }
public abstract int ERR_EncUpdateFailedMissingAttribute { get; }
public abstract void ReportInvalidAttributeArgument(DiagnosticBag diagnostics, SyntaxNode attributeSyntax, int parameterIndex, AttributeData attribute);
public abstract void ReportInvalidNamedArgument(DiagnosticBag diagnostics, SyntaxNode attributeSyntax, int namedArgumentIndex, ITypeSymbol attributeClass, string parameterName);
......
......@@ -356,7 +356,7 @@ protected object[] GetArgumentsToUse(IFormatProvider formatProvider)
if (symbol != null)
{
argumentsToUse = InitializeArgumentListIfNeeded(argumentsToUse);
argumentsToUse[i] = _messageProvider.ConvertSymbolToString(_errorCode, symbol);
argumentsToUse[i] = _messageProvider.GetErrorDisplayString(symbol);
}
}
......
......@@ -194,8 +194,7 @@ private bool TryGetPreviousLocalId(SyntaxNode currentDeclarator, LocalDebugId cu
// Should rarely happen since the IDE reports a rude edit if the attribute type doesn't exist.
if (_hoistedLocalSlotsOpt == null)
{
// TODO: better error message https://github.com/dotnet/roslyn/issues/9196
diagnostics.Add(_messageProvider.CreateDiagnostic(_messageProvider.ERR_ModuleEmitFailure, NoLocation.Singleton, _previousTopLevelMethod.ContainingModule.Name));
ReportMissingStateMachineAttribute(diagnostics);
slotIndex = -1;
return false;
}
......@@ -230,8 +229,7 @@ public override bool TryGetPreviousAwaiterSlotIndex(Cci.ITypeReference currentTy
// Should rarely happen since the IDE reports a rude edit if the attribute type doesn't exist.
if (_awaiterMapOpt == null)
{
// TODO: better error message https://github.com/dotnet/roslyn/issues/9196
diagnostics.Add(_messageProvider.CreateDiagnostic(_messageProvider.ERR_ModuleEmitFailure, NoLocation.Singleton, _previousTopLevelMethod.ContainingModule.Name));
ReportMissingStateMachineAttribute(diagnostics);
slotIndex = -1;
return false;
}
......@@ -239,6 +237,16 @@ public override bool TryGetPreviousAwaiterSlotIndex(Cci.ITypeReference currentTy
return _awaiterMapOpt.TryGetValue(_symbolMap.MapReference(currentType), out slotIndex);
}
private void ReportMissingStateMachineAttribute(DiagnosticBag diagnostics)
{
diagnostics.Add(_messageProvider.CreateDiagnostic(
_messageProvider.ERR_EncUpdateFailedMissingAttribute,
NoLocation.Singleton,
_messageProvider.GetErrorDisplayString(_previousTopLevelMethod),
(_previousTopLevelMethod.IsAsync ? AttributeDescription.AsyncStateMachineAttribute : AttributeDescription.IteratorStateMachineAttribute).FullName));
}
private bool TryGetPreviousSyntaxOffset(SyntaxNode currentSyntax, out int previousSyntaxOffset)
{
// no syntax map
......
......@@ -177,9 +177,7 @@ private static string ResolveRelativePath(PathKind kind, string path, string bas
return path;
default:
// EDMAURER this is not using ExceptionUtilities.UnexpectedValue() because this file
// is shared via linking with other code that doesn't have the ExceptionUtilities.
throw new InvalidOperationException(string.Format("Unexpected PathKind {0}.", kind));
throw ExceptionUtilities.UnexpectedValue(kind);
}
}
......
......@@ -514,8 +514,8 @@ internal bool IsBound
if (lazyBuilder.ContainsKey(sourceIdentity))
{
// TODO: localize message, report as diagnostic (https://github.com/dotnet/roslyn/issues/8910)
throw new NotSupportedException("The compilation references multiple assemblies whose versions only differ in auto-generated build and/or revision numbers.");
// The compilation references multiple assemblies whose versions only differ in auto-generated build and/or revision numbers.
throw new NotSupportedException(CodeAnalysisResources.CompilationReferencesAssembliesWithDifferentAutoGeneratedVersion);
}
lazyBuilder.Add(sourceIdentity, originalIdentity);
......
......@@ -1605,6 +1605,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ERR_PublicKeyContainerFailure = 36981
ERR_InvalidAssemblyCulture = 36982
ERR_EncUpdateFailedMissingAttribute = 36983
ERR_CantAwaitAsyncSub1 = 37001
ERR_ResumableLambdaInExpressionTree = 37050
......
......@@ -95,7 +95,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return New VBDiagnostic(ErrorFactory.ErrorInfo(CType(code, ERRID), args), location)
End Function
Public Overrides Function ConvertSymbolToString(errorCode As Integer, symbol As ISymbol) As String
Public Overrides Function GetErrorDisplayString(symbol As ISymbol) As String
' show extra info for assembly if possible such as version, public key token etc.
If symbol.Kind = SymbolKind.Assembly OrElse symbol.Kind = SymbolKind.Namespace Then
Return symbol.ToString()
......@@ -498,6 +498,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return ERRID.ERR_ModuleEmitFailure
End Get
End Property
Public Overrides ReadOnly Property ERR_EncUpdateFailedMissingAttribute As Integer
Get
Return ERRID.ERR_EncUpdateFailedMissingAttribute
End Get
End Property
End Class
End Namespace
......@@ -3296,6 +3296,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to Cannot update &apos;{0}&apos;; attribute &apos;{1}&apos; is missing..
'''</summary>
Friend ReadOnly Property ERR_EncUpdateFailedMissingAttribute() As String
Get
Return ResourceManager.GetString("ERR_EncUpdateFailedMissingAttribute", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to &apos;End Class&apos; must be preceded by a matching &apos;Class&apos;..
'''</summary>
......
......@@ -818,6 +818,9 @@
<data name="ERR_ModuleEmitFailure" xml:space="preserve">
<value>Failed to emit module '{0}'.</value>
</data>
<data name="ERR_EncUpdateFailedMissingAttribute" xml:space="preserve">
<value>Cannot update '{0}'; attribute '{1}' is missing.</value>
</data>
<data name="ERR_OverrideNotNeeded3" xml:space="preserve">
<value>{0} '{1}' cannot be declared 'Overrides' because it does not override a {0} in a base class.</value>
</data>
......
......@@ -4447,7 +4447,7 @@ End Class
ImmutableArray.Create(New SemanticEdit(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables:=True)))
diff1.EmitResult.Diagnostics.Verify(
Diagnostic(ERRID.ERR_ModuleEmitFailure).WithArguments(compilation0.SourceModule.Name))
Diagnostic(ERRID.ERR_EncUpdateFailedMissingAttribute).WithArguments("Public Function F() As IEnumerable(Of Integer)", "System.Runtime.CompilerServices.IteratorStateMachineAttribute"))
End Sub
<Fact, WorkItem(9119, "https://github.com/dotnet/roslyn/issues/9119")>
......@@ -4501,8 +4501,8 @@ End Class
ImmutableArray.Create(New SemanticEdit(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables:=True)))
diff1.EmitResult.Diagnostics.Verify(
Diagnostic(ERRID.ERR_ModuleEmitFailure).WithArguments(compilation0.SourceModule.Name),
Diagnostic(ERRID.ERR_ModuleEmitFailure).WithArguments(compilation0.SourceModule.Name))
Diagnostic(ERRID.ERR_EncUpdateFailedMissingAttribute).WithArguments("Public Function F() As Task(Of Integer)", "System.Runtime.CompilerServices.AsyncStateMachineAttribute"),
Diagnostic(ERRID.ERR_EncUpdateFailedMissingAttribute).WithArguments("Public Function F() As Task(Of Integer)", "System.Runtime.CompilerServices.AsyncStateMachineAttribute"))
End Sub
End Class
End Namespace
......@@ -81,8 +81,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
Return String.Empty
End Function
Public Overrides Function ConvertSymbolToString(errorCode As Integer, symbol As ISymbol) As String
Return MessageProvider.Instance.ConvertSymbolToString(errorCode, symbol)
Public Overrides Function GetErrorDisplayString(symbol As ISymbol) As String
Return MessageProvider.Instance.GetErrorDisplayString(symbol)
End Function
End Class
......
......@@ -1030,8 +1030,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests
Return 0
End Function
Public Overrides Function ConvertSymbolToString(errorCode As Integer, symbol As ISymbol) As String
Return MessageProvider.Instance.ConvertSymbolToString(errorCode, symbol)
Public Overrides Function GetErrorDisplayString(symbol As ISymbol) As String
Return MessageProvider.Instance.GetErrorDisplayString(symbol)
End Function
End Class
......
......@@ -80,9 +80,7 @@ internal static class RudeEditDiagnosticDescriptors
{ GetDescriptorPair(RudeEditKind.PartiallyExecutedActiveStatementDelete, FeaturesResources.AnActiveStatementHasBeenRemoved) },
{ GetDescriptorPair(RudeEditKind.InsertFile, FeaturesResources.AddingANewFile) },
{ GetDescriptorPair(RudeEditKind.UpdatingStateMachineMethodAroundActiveStatement, FeaturesResources.UpdatingStateMachineMethodAroundActive) },
// TODO: move message to resources https://github.com/dotnet/roslyn/issues/9196
{ GetDescriptorPair(RudeEditKind.UpdatingStateMachineMethodMissingAttribute, "Attribute '{0}' is missing. Updating an async method or an iterator will prevent the debug session from continuing.") },
{ GetDescriptorPair(RudeEditKind.UpdatingStateMachineMethodMissingAttribute, FeaturesResources.UpdatingStateMachineMethodMissingAttribute) },
{ GetDescriptorPair(RudeEditKind.RUDE_EDIT_COMPLEX_QUERY_EXPRESSION, FeaturesResources.ModifyingAWhichContainsComplexQuery) },
// VB specific,
......
......@@ -2322,6 +2322,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Attribute &apos;{0}&apos; is missing. Updating an async method or an iterator will prevent the debug session from continuing..
/// </summary>
internal static string UpdatingStateMachineMethodMissingAttribute {
get {
return ResourceManager.GetString("UpdatingStateMachineMethodMissingAttribute", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Updating the alias of Declare Statement will prevent the debug session from continuing..
/// </summary>
......
......@@ -574,6 +574,9 @@
<data name="AddingANewFile" xml:space="preserve">
<value>Adding a new file will prevent the debug session from continuing.</value>
</data>
<data name="UpdatingStateMachineMethodMissingAttribute" xml:space="preserve">
<value>Attribute '{0}' is missing. Updating an async method or an iterator will prevent the debug session from continuing.</value>
</data>
<data name="UnexpectedInterfaceMemberKind" xml:space="preserve">
<value>Unexpected interface member kind: {0}</value>
</data>
......
......@@ -386,5 +386,13 @@ public override int ERR_ModuleEmitFailure
throw new NotImplementedException();
}
}
public override int ERR_EncUpdateFailedMissingAttribute
{
get
{
throw new NotImplementedException();
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册