mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Change the 'SaveError' method in Parser to use nameof for error ids (#6498)
Many error messages in PowerShell currently use a LINQ expression to pass both the name of the error and the message through in the error processing. This PR uses the `nameof` feature to carry the error name/ID and gets rid of LINQ expression reflection, hopefully improving performance, especially in editor scenarios.
This commit is contained in:
@@ -1137,7 +1137,7 @@ namespace System.Management.Automation
|
||||
null,
|
||||
null,
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
"ParameterAlreadyBound");
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound));
|
||||
|
||||
// Multiple values assigned to the same parameter.
|
||||
// Not caused by default parameter binding
|
||||
|
||||
@@ -587,7 +587,7 @@ namespace System.Management.Automation.Language
|
||||
null,
|
||||
null,
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
"ParameterAlreadyBound");
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound));
|
||||
// if the duplicated Parameter Name appears more than twice, we will ignore as we already have similar bindingException.
|
||||
if (!BindingExceptions.ContainsKey(duplicateParameter.ParameterName))
|
||||
{
|
||||
|
||||
@@ -3667,7 +3667,7 @@ namespace System.Management.Automation
|
||||
|
||||
if (adapterData.readOnly)
|
||||
{
|
||||
throw new SetValueException("ReadOnlyProperty",
|
||||
throw new SetValueException(nameof(ExtendedTypeSystem.ReadOnlyProperty),
|
||||
null,
|
||||
ExtendedTypeSystem.ReadOnlyProperty,
|
||||
adapterData.member.Name);
|
||||
|
||||
@@ -443,7 +443,7 @@ namespace System.Management.Automation
|
||||
null,
|
||||
null,
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
"ParameterAlreadyBound");
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound));
|
||||
|
||||
throw bindingException;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,10 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
if (!LanguagePrimitives.TryConvertTo(arg, type, out result))
|
||||
{
|
||||
parser.ReportError(errorExtent, () => ParserStrings.CannotConvertValue, ToStringCodeMethods.Type(type));
|
||||
parser.ReportError(errorExtent,
|
||||
nameof(ParserStrings.CannotConvertValue),
|
||||
ParserStrings.CannotConvertValue,
|
||||
ToStringCodeMethods.Type(type));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -307,7 +310,10 @@ namespace System.Management.Automation.Language
|
||||
|
||||
if (firstBaseTypeAst.TypeName.IsArray)
|
||||
{
|
||||
parser.ReportError(firstBaseTypeAst.Extent, () => ParserStrings.SubtypeArray, firstBaseTypeAst.TypeName.FullName);
|
||||
parser.ReportError(firstBaseTypeAst.Extent,
|
||||
nameof(ParserStrings.SubtypeArray),
|
||||
ParserStrings.SubtypeArray,
|
||||
firstBaseTypeAst.TypeName.FullName);
|
||||
// fall to the default base type
|
||||
}
|
||||
else
|
||||
@@ -315,7 +321,10 @@ namespace System.Management.Automation.Language
|
||||
baseClass = firstBaseTypeAst.TypeName.GetReflectionType();
|
||||
if (baseClass == null)
|
||||
{
|
||||
parser.ReportError(firstBaseTypeAst.Extent, () => ParserStrings.TypeNotFound, firstBaseTypeAst.TypeName.FullName);
|
||||
parser.ReportError(firstBaseTypeAst.Extent,
|
||||
nameof(ParserStrings.TypeNotFound),
|
||||
ParserStrings.TypeNotFound,
|
||||
firstBaseTypeAst.TypeName.FullName);
|
||||
// fall to the default base type
|
||||
}
|
||||
else
|
||||
@@ -323,13 +332,19 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (baseClass.GetTypeInfo().IsSealed)
|
||||
{
|
||||
parser.ReportError(firstBaseTypeAst.Extent, () => ParserStrings.SealedBaseClass, baseClass.Name);
|
||||
parser.ReportError(firstBaseTypeAst.Extent,
|
||||
nameof(ParserStrings.SealedBaseClass),
|
||||
ParserStrings.SealedBaseClass,
|
||||
baseClass.Name);
|
||||
// ignore base type if it's sealed.
|
||||
baseClass = null;
|
||||
}
|
||||
else if (baseClass.GetTypeInfo().IsGenericType && !baseClass.IsConstructedGenericType)
|
||||
{
|
||||
parser.ReportError(firstBaseTypeAst.Extent, () => ParserStrings.SubtypeUnclosedGeneric, baseClass.Name);
|
||||
parser.ReportError(firstBaseTypeAst.Extent,
|
||||
nameof(ParserStrings.SubtypeUnclosedGeneric),
|
||||
ParserStrings.SubtypeUnclosedGeneric,
|
||||
baseClass.Name);
|
||||
// ignore base type, we cannot inherit from unclosed generic.
|
||||
baseClass = null;
|
||||
}
|
||||
@@ -361,7 +376,10 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (baseTypeAsts[i].TypeName.IsArray)
|
||||
{
|
||||
parser.ReportError(baseTypeAsts[i].Extent, () => ParserStrings.SubtypeArray, baseTypeAsts[i].TypeName.FullName);
|
||||
parser.ReportError(baseTypeAsts[i].Extent,
|
||||
nameof(ParserStrings.SubtypeArray),
|
||||
ParserStrings.SubtypeArray,
|
||||
baseTypeAsts[i].TypeName.FullName);
|
||||
this.HasFatalErrors = true;
|
||||
}
|
||||
}
|
||||
@@ -370,14 +388,20 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (baseTypeAsts[i].TypeName.IsArray)
|
||||
{
|
||||
parser.ReportError(baseTypeAsts[i].Extent, () => ParserStrings.SubtypeArray, baseTypeAsts[i].TypeName.FullName);
|
||||
parser.ReportError(baseTypeAsts[i].Extent,
|
||||
nameof(ParserStrings.SubtypeArray),
|
||||
ParserStrings.SubtypeArray,
|
||||
baseTypeAsts[i].TypeName.FullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Type interfaceType = baseTypeAsts[i].TypeName.GetReflectionType();
|
||||
if (interfaceType == null)
|
||||
{
|
||||
parser.ReportError(baseTypeAsts[i].Extent, () => ParserStrings.TypeNotFound, baseTypeAsts[i].TypeName.FullName);
|
||||
parser.ReportError(baseTypeAsts[i].Extent,
|
||||
nameof(ParserStrings.TypeNotFound),
|
||||
ParserStrings.TypeNotFound,
|
||||
baseTypeAsts[i].TypeName.FullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -387,7 +411,10 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.ReportError(baseTypeAsts[i].Extent, () => ParserStrings.InterfaceNameExpected, interfaceType.Name);
|
||||
parser.ReportError(baseTypeAsts[i].Extent,
|
||||
nameof(ParserStrings.InterfaceNameExpected),
|
||||
ParserStrings.InterfaceNameExpected,
|
||||
interfaceType.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,7 +521,10 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (!instanceCtors.Any())
|
||||
{
|
||||
_parser.ReportError(_typeDefinitionAst.Extent, () => ParserStrings.BaseClassNoDefaultCtor, _typeBuilder.BaseType.Name);
|
||||
_parser.ReportError(_typeDefinitionAst.Extent,
|
||||
nameof(ParserStrings.BaseClassNoDefaultCtor),
|
||||
ParserStrings.BaseClassNoDefaultCtor,
|
||||
_typeBuilder.BaseType.Name);
|
||||
this.HasFatalErrors = true;
|
||||
}
|
||||
}
|
||||
@@ -504,7 +534,10 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (_definedProperties.ContainsKey(propertyMemberAst.Name))
|
||||
{
|
||||
_parser.ReportError(propertyMemberAst.Extent, () => ParserStrings.MemberAlreadyDefined, propertyMemberAst.Name);
|
||||
_parser.ReportError(propertyMemberAst.Extent,
|
||||
nameof(ParserStrings.MemberAlreadyDefined),
|
||||
ParserStrings.MemberAlreadyDefined,
|
||||
propertyMemberAst.Name);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -658,7 +691,9 @@ namespace System.Management.Automation.Language
|
||||
!functionMemberAst.IsConstructor)
|
||||
{
|
||||
_parser.ReportError(functionMemberAst.NameExtent ?? functionMemberAst.Extent,
|
||||
() => ParserStrings.MemberAlreadyDefined, functionMemberAst.Name);
|
||||
nameof(ParserStrings.MemberAlreadyDefined),
|
||||
ParserStrings.MemberAlreadyDefined,
|
||||
functionMemberAst.Name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -687,12 +722,17 @@ namespace System.Management.Automation.Language
|
||||
: typeof(object);
|
||||
if (paramType == null)
|
||||
{
|
||||
_parser.ReportError(typeConstraint.Extent, () => ParserStrings.TypeNotFound, typeConstraint.TypeName.FullName);
|
||||
_parser.ReportError(typeConstraint.Extent,
|
||||
nameof(ParserStrings.TypeNotFound),
|
||||
ParserStrings.TypeNotFound,
|
||||
typeConstraint.TypeName.FullName);
|
||||
anyErrors = true;
|
||||
}
|
||||
else if (paramType == typeof(void) || paramType.GetTypeInfo().IsGenericTypeDefinition)
|
||||
{
|
||||
_parser.ReportError(typeConstraint.Extent, () => ParserStrings.TypeNotAllowedForParameter,
|
||||
_parser.ReportError(typeConstraint.Extent,
|
||||
nameof(ParserStrings.TypeNotAllowedForParameter),
|
||||
ParserStrings.TypeNotAllowedForParameter,
|
||||
typeConstraint.TypeName.FullName);
|
||||
anyErrors = true;
|
||||
}
|
||||
@@ -735,7 +775,10 @@ namespace System.Management.Automation.Language
|
||||
var parameters = functionMemberAst.Parameters;
|
||||
if (parameters.Count > 0)
|
||||
{
|
||||
_parser.ReportError(Parser.ExtentOf(parameters.First(), parameters.Last()), () => ParserStrings.StaticConstructorCantHaveParameters);
|
||||
IScriptExtent errorExtent = Parser.ExtentOf(parameters.First(), parameters.Last());
|
||||
_parser.ReportError(errorExtent,
|
||||
nameof(ParserStrings.StaticConstructorCantHaveParameters),
|
||||
ParserStrings.StaticConstructorCantHaveParameters);
|
||||
return;
|
||||
}
|
||||
methodAttributes |= Reflection.MethodAttributes.Static;
|
||||
@@ -763,7 +806,10 @@ namespace System.Management.Automation.Language
|
||||
var returnType = functionMemberAst.GetReturnType();
|
||||
if (returnType == null)
|
||||
{
|
||||
_parser.ReportError(functionMemberAst.ReturnType.Extent, () => ParserStrings.TypeNotFound, functionMemberAst.ReturnType.TypeName.FullName);
|
||||
_parser.ReportError(functionMemberAst.ReturnType.Extent,
|
||||
nameof(ParserStrings.TypeNotFound),
|
||||
ParserStrings.TypeNotFound,
|
||||
functionMemberAst.ReturnType.TypeName.FullName);
|
||||
return;
|
||||
}
|
||||
var method = _typeBuilder.DefineMethod(functionMemberAst.Name, attributes, returnType, parameterTypes);
|
||||
@@ -1019,7 +1065,9 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (!result.Contains(helper))
|
||||
{
|
||||
parser.ReportError(helper._enumDefinitionAst.Extent, () => ParserStrings.CycleInEnumInitializers);
|
||||
parser.ReportError(helper._enumDefinitionAst.Extent,
|
||||
nameof(ParserStrings.CycleInEnumInitializers),
|
||||
ParserStrings.CycleInEnumInitializers);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1057,11 +1105,15 @@ namespace System.Management.Automation.Language
|
||||
if (constValue != null &&
|
||||
LanguagePrimitives.IsNumeric(LanguagePrimitives.GetTypeCode(constValue.GetType())))
|
||||
{
|
||||
_parser.ReportError(enumerator.InitialValue.Extent, () => ParserStrings.EnumeratorValueTooLarge);
|
||||
_parser.ReportError(enumerator.InitialValue.Extent,
|
||||
nameof(ParserStrings.EnumeratorValueTooLarge),
|
||||
ParserStrings.EnumeratorValueTooLarge);
|
||||
}
|
||||
else
|
||||
{
|
||||
_parser.ReportError(enumerator.InitialValue.Extent, () => ParserStrings.CannotConvertValue,
|
||||
_parser.ReportError(enumerator.InitialValue.Extent,
|
||||
nameof(ParserStrings.CannotConvertValue),
|
||||
ParserStrings.CannotConvertValue,
|
||||
ToStringCodeMethods.Type(typeof(int)));
|
||||
}
|
||||
}
|
||||
@@ -1069,17 +1121,24 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
else
|
||||
{
|
||||
_parser.ReportError(enumerator.InitialValue.Extent, () => ParserStrings.EnumeratorValueMustBeConstant);
|
||||
_parser.ReportError(enumerator.InitialValue.Extent,
|
||||
nameof(ParserStrings.EnumeratorValueMustBeConstant),
|
||||
ParserStrings.EnumeratorValueMustBeConstant);
|
||||
}
|
||||
}
|
||||
else if (valueTooBig)
|
||||
{
|
||||
_parser.ReportError(enumerator.Extent, () => ParserStrings.EnumeratorValueTooLarge);
|
||||
_parser.ReportError(enumerator.Extent,
|
||||
nameof(ParserStrings.EnumeratorValueTooLarge),
|
||||
ParserStrings.EnumeratorValueTooLarge);
|
||||
}
|
||||
|
||||
if (definedEnumerators.Contains(enumerator.Name))
|
||||
{
|
||||
_parser.ReportError(enumerator.Extent, () => ParserStrings.MemberAlreadyDefined, enumerator.Name);
|
||||
_parser.ReportError(enumerator.Extent,
|
||||
nameof(ParserStrings.MemberAlreadyDefined),
|
||||
ParserStrings.MemberAlreadyDefined,
|
||||
enumerator.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1204,8 +1263,11 @@ namespace System.Management.Automation.Language
|
||||
//
|
||||
// Presumably this catch could go away when we will not create Type at parse time.
|
||||
// Error checking should be moved/added to semantic checks.
|
||||
parser.ReportError(helper._typeDefinitionAst.Extent, () => ParserStrings.TypeCreationError,
|
||||
helper._typeBuilder.Name, e.Message);
|
||||
parser.ReportError(helper._typeDefinitionAst.Extent,
|
||||
nameof(ParserStrings.TypeCreationError),
|
||||
ParserStrings.TypeCreationError,
|
||||
helper._typeBuilder.Name,
|
||||
e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -92,7 +92,10 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.ReportError(typeDefinitionAst.Extent, () => ParserStrings.MemberAlreadyDefined, typeDefinitionAst.Name);
|
||||
parser.ReportError(typeDefinitionAst.Extent,
|
||||
nameof(ParserStrings.MemberAlreadyDefined),
|
||||
ParserStrings.MemberAlreadyDefined,
|
||||
typeDefinitionAst.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -125,7 +128,10 @@ namespace System.Management.Automation.Language
|
||||
string fullName = SymbolResolver.GetModuleQualifiedName(moduleInfo.Name, typeDefinitionAst.Name);
|
||||
if (_typeTable.TryGetValue(fullName, out result))
|
||||
{
|
||||
parser.ReportError(typeDefinitionAst.Extent, () => ParserStrings.MemberAlreadyDefined, fullName);
|
||||
parser.ReportError(typeDefinitionAst.Extent,
|
||||
nameof(ParserStrings.MemberAlreadyDefined),
|
||||
ParserStrings.MemberAlreadyDefined,
|
||||
fullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -393,12 +399,21 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
var typeAst = _symbolTable.GetCurrentTypeDefinitionAst();
|
||||
Diagnostics.Assert(typeAst != null, "Method scopes can exist only inside type definitions.");
|
||||
_parser.ReportError(variableExpressionAst.Extent, () => ParserStrings.MissingTypeInStaticPropertyAssignment,
|
||||
String.Format(CultureInfo.InvariantCulture, "[{0}]::", typeAst.Name), propertyMember.Name);
|
||||
|
||||
string typeString = String.Format(CultureInfo.InvariantCulture, "[{0}]::", typeAst.Name);
|
||||
_parser.ReportError(variableExpressionAst.Extent,
|
||||
nameof(ParserStrings.MissingTypeInStaticPropertyAssignment),
|
||||
ParserStrings.MissingTypeInStaticPropertyAssignment,
|
||||
typeString,
|
||||
propertyMember.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
_parser.ReportError(variableExpressionAst.Extent, () => ParserStrings.MissingThis, "$this.", propertyMember.Name);
|
||||
_parser.ReportError(variableExpressionAst.Extent,
|
||||
nameof(ParserStrings.MissingThis),
|
||||
ParserStrings.MissingThis,
|
||||
"$this.",
|
||||
propertyMember.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -521,16 +536,23 @@ namespace System.Management.Automation.Language
|
||||
var moduleInfo = GetModulesFromUsingModule(usingStatementAst, out exception, out wildcardCharactersUsed, out isConstant);
|
||||
if (!isConstant)
|
||||
{
|
||||
_parser.ReportError(usingStatementAst.Extent, () => ParserStrings.RequiresArgumentMustBeConstant);
|
||||
_parser.ReportError(usingStatementAst.Extent,
|
||||
nameof(ParserStrings.RequiresArgumentMustBeConstant),
|
||||
ParserStrings.RequiresArgumentMustBeConstant);
|
||||
}
|
||||
else if (exception != null)
|
||||
{
|
||||
// we re-using RequiresModuleInvalid string, semantic is very similar so it's fine to do that.
|
||||
_parser.ReportError(usingStatementAst.Extent, () => ParserStrings.RequiresModuleInvalid, exception.Message);
|
||||
_parser.ReportError(usingStatementAst.Extent,
|
||||
nameof(ParserStrings.RequiresModuleInvalid),
|
||||
ParserStrings.RequiresModuleInvalid,
|
||||
exception.Message);
|
||||
}
|
||||
else if (wildcardCharactersUsed)
|
||||
{
|
||||
_parser.ReportError(usingStatementAst.Extent, () => ParserStrings.WildCardModuleNameError);
|
||||
_parser.ReportError(usingStatementAst.Extent,
|
||||
nameof(ParserStrings.WildCardModuleNameError),
|
||||
ParserStrings.WildCardModuleNameError);
|
||||
}
|
||||
else if (moduleInfo != null && moduleInfo.Count > 0)
|
||||
{
|
||||
@@ -549,7 +571,10 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
// if there is no exception, but we didn't find the module then it's not present
|
||||
string moduleText = usingStatementAst.Name != null ? usingStatementAst.Name.Value : usingStatementAst.ModuleSpecification.Extent.Text;
|
||||
_parser.ReportError(usingStatementAst.Extent, () => ParserStrings.ModuleNotFoundDuringParse, moduleText);
|
||||
_parser.ReportError(usingStatementAst.Extent,
|
||||
nameof(ParserStrings.ModuleNotFoundDuringParse),
|
||||
ParserStrings.ModuleNotFoundDuringParse,
|
||||
moduleText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,7 +632,9 @@ namespace System.Management.Automation.Language
|
||||
|
||||
if (classDefn != null && classDefn.IsAmbiguous())
|
||||
{
|
||||
_parser.ReportError(typeName.Extent, () => ParserStrings.AmbiguousTypeReference,
|
||||
_parser.ReportError(typeName.Extent,
|
||||
nameof(ParserStrings.AmbiguousTypeReference),
|
||||
ParserStrings.AmbiguousTypeReference,
|
||||
typeName.Name,
|
||||
GetModuleQualifiedName(classDefn.ExternalNamespaces[0], typeName.Name),
|
||||
GetModuleQualifiedName(classDefn.ExternalNamespaces[1], typeName.Name));
|
||||
@@ -631,10 +658,19 @@ namespace System.Management.Automation.Language
|
||||
// [ordered] is an attribute, but it's looks like a type constraint.
|
||||
if (!typeName.FullName.Equals(LanguagePrimitives.OrderedAttribute, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_parser.ReportError(typeName.Extent,
|
||||
isAttribute
|
||||
? (Expression<Func<string>>)(() => ParserStrings.CustomAttributeTypeNotFound)
|
||||
: () => ParserStrings.TypeNotFound, typeName.Name);
|
||||
string errorId;
|
||||
string errorMsg;
|
||||
if (isAttribute)
|
||||
{
|
||||
errorId = nameof(ParserStrings.CustomAttributeTypeNotFound);
|
||||
errorMsg = ParserStrings.CustomAttributeTypeNotFound;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorId = nameof(ParserStrings.TypeNotFound);
|
||||
errorMsg = ParserStrings.TypeNotFound;
|
||||
}
|
||||
_parser.ReportError(typeName.Extent, errorId, errorMsg, typeName.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -716,4 +752,4 @@ namespace System.Management.Automation.Language
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -980,38 +980,40 @@ namespace System.Management.Automation.Language
|
||||
|
||||
if (_beginSignatureExtent.StartOffset < ast.Extent.StartOffset)
|
||||
{
|
||||
ReportError(ast.Extent, () => ParserStrings.TokenAfterEndOfValidScriptText);
|
||||
ReportError(ast.Extent,
|
||||
nameof(ParserStrings.TokenAfterEndOfValidScriptText),
|
||||
ParserStrings.TokenAfterEndOfValidScriptText);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportError(int errorOffset, Expression<Func<string>> message, params object[] args)
|
||||
private void ReportError(int errorOffset, string errorId, string errorMsg, params object[] args)
|
||||
{
|
||||
_parser.ReportError(NewScriptExtent(errorOffset, errorOffset + 1), message, args);
|
||||
_parser.ReportError(NewScriptExtent(errorOffset, errorOffset + 1), errorId, errorMsg, args);
|
||||
}
|
||||
|
||||
private void ReportError(IScriptExtent extent, Expression<Func<string>> message)
|
||||
private void ReportError(IScriptExtent extent, string errorId, string errorMsg)
|
||||
{
|
||||
_parser.ReportError(extent, message);
|
||||
_parser.ReportError(extent, errorId, errorMsg);
|
||||
}
|
||||
|
||||
private void ReportError(IScriptExtent extent, Expression<Func<string>> message, object arg)
|
||||
private void ReportError(IScriptExtent extent, string errorId, string errorMsg, object arg)
|
||||
{
|
||||
_parser.ReportError(extent, message, arg);
|
||||
_parser.ReportError(extent, errorId, errorMsg, arg);
|
||||
}
|
||||
|
||||
private void ReportError(IScriptExtent extent, Expression<Func<string>> message, object arg1, object arg2)
|
||||
private void ReportError(IScriptExtent extent, string errorId, string errorMsg, object arg1, object arg2)
|
||||
{
|
||||
_parser.ReportError(extent, message, arg1, arg2);
|
||||
_parser.ReportError(extent, errorId, errorMsg, arg1, arg2);
|
||||
}
|
||||
|
||||
private void ReportIncompleteInput(int errorOffset, Expression<Func<string>> message)
|
||||
private void ReportIncompleteInput(int errorOffset, string errorId, string errorMsg)
|
||||
{
|
||||
_parser.ReportIncompleteInput(NewScriptExtent(errorOffset, _currentIndex), message);
|
||||
_parser.ReportIncompleteInput(NewScriptExtent(errorOffset, _currentIndex), errorId, errorMsg);
|
||||
}
|
||||
|
||||
private void ReportIncompleteInput(int errorOffset, Expression<Func<string>> message, object arg)
|
||||
private void ReportIncompleteInput(int errorOffset, string errorId, string errorMsg, object arg)
|
||||
{
|
||||
_parser.ReportIncompleteInput(NewScriptExtent(errorOffset, _currentIndex), message, arg);
|
||||
_parser.ReportIncompleteInput(NewScriptExtent(errorOffset, _currentIndex), errorId, errorMsg, arg);
|
||||
}
|
||||
|
||||
private InternalScriptExtent NewScriptExtent(int start, int end)
|
||||
@@ -1259,7 +1261,9 @@ namespace System.Management.Automation.Language
|
||||
UngetChar();
|
||||
|
||||
IScriptExtent errorExtent = NewScriptExtent(escSeqStartIndex, _currentIndex);
|
||||
ReportError(errorExtent, () => ParserStrings.InvalidUnicodeEscapeSequence);
|
||||
ReportError(errorExtent,
|
||||
nameof(ParserStrings.InvalidUnicodeEscapeSequence),
|
||||
ParserStrings.InvalidUnicodeEscapeSequence);
|
||||
return s_invalidChar;
|
||||
}
|
||||
|
||||
@@ -1278,7 +1282,9 @@ namespace System.Management.Automation.Language
|
||||
// Sequence must have at least one hex char.
|
||||
Release(sb);
|
||||
IScriptExtent errorExtent = NewScriptExtent(escSeqStartIndex, _currentIndex);
|
||||
ReportError(errorExtent, () => ParserStrings.InvalidUnicodeEscapeSequence);
|
||||
ReportError(errorExtent,
|
||||
nameof(ParserStrings.InvalidUnicodeEscapeSequence),
|
||||
ParserStrings.InvalidUnicodeEscapeSequence);
|
||||
return s_invalidChar;
|
||||
}
|
||||
|
||||
@@ -1289,17 +1295,27 @@ namespace System.Management.Automation.Language
|
||||
UngetChar();
|
||||
|
||||
Release(sb);
|
||||
ReportError(_currentIndex,
|
||||
i < s_maxNumberOfUnicodeHexDigits
|
||||
? (Expression<Func<string>>)(() => ParserStrings.InvalidUnicodeEscapeSequence)
|
||||
: () => ParserStrings.MissingUnicodeEscapeSequenceTerminator);
|
||||
if (i < s_maxNumberOfUnicodeHexDigits)
|
||||
{
|
||||
ReportError(_currentIndex,
|
||||
nameof(ParserStrings.InvalidUnicodeEscapeSequence),
|
||||
ParserStrings.InvalidUnicodeEscapeSequence);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportError(_currentIndex,
|
||||
nameof(ParserStrings.MissingUnicodeEscapeSequenceTerminator),
|
||||
ParserStrings.MissingUnicodeEscapeSequenceTerminator);
|
||||
}
|
||||
return s_invalidChar;
|
||||
}
|
||||
else if (i == s_maxNumberOfUnicodeHexDigits) {
|
||||
UngetChar();
|
||||
|
||||
Release(sb);
|
||||
ReportError(_currentIndex, () => ParserStrings.TooManyDigitsInUnicodeEscapeSequence);
|
||||
ReportError(_currentIndex,
|
||||
nameof(ParserStrings.TooManyDigitsInUnicodeEscapeSequence),
|
||||
ParserStrings.TooManyDigitsInUnicodeEscapeSequence);
|
||||
return s_invalidChar;
|
||||
}
|
||||
|
||||
@@ -1321,7 +1337,9 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
// Place the error indicator under only the hex digits in the esc sequence.
|
||||
IScriptExtent errorExtent = NewScriptExtent(escSeqStartIndex + 3, _currentIndex - 1);
|
||||
ReportError(errorExtent, () => ParserStrings.InvalidUnicodeEscapeSequenceValue);
|
||||
ReportError(errorExtent,
|
||||
nameof(ParserStrings.InvalidUnicodeEscapeSequenceValue),
|
||||
ParserStrings.InvalidUnicodeEscapeSequenceValue);
|
||||
return s_invalidChar;
|
||||
}
|
||||
}
|
||||
@@ -1547,7 +1565,9 @@ namespace System.Management.Automation.Language
|
||||
else if (c == '\0' && AtEof())
|
||||
{
|
||||
UngetChar();
|
||||
ReportIncompleteInput(errorIndex, () => ParserStrings.MissingTerminatorMultiLineComment);
|
||||
ReportIncompleteInput(errorIndex,
|
||||
nameof(ParserStrings.MissingTerminatorMultiLineComment),
|
||||
ParserStrings.MissingTerminatorMultiLineComment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1643,7 +1663,9 @@ namespace System.Management.Automation.Language
|
||||
var commandName = commandAst.GetCommandName();
|
||||
if (!string.Equals(commandName, "requires", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ReportError(commandAst.Extent, () => DiscoveryExceptions.ScriptRequiresInvalidFormat);
|
||||
ReportError(commandAst.Extent,
|
||||
nameof(DiscoveryExceptions.ScriptRequiresInvalidFormat),
|
||||
DiscoveryExceptions.ScriptRequiresInvalidFormat);
|
||||
}
|
||||
|
||||
var snapinSpecified = false;
|
||||
@@ -1674,7 +1696,9 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportError(commandAst.CommandElements[i].Extent, () => DiscoveryExceptions.ScriptRequiresInvalidFormat);
|
||||
ReportError(commandAst.CommandElements[i].Extent,
|
||||
nameof(DiscoveryExceptions.ScriptRequiresInvalidFormat),
|
||||
DiscoveryExceptions.ScriptRequiresInvalidFormat);
|
||||
}
|
||||
}
|
||||
if (snapinName != null)
|
||||
@@ -1733,21 +1757,29 @@ namespace System.Management.Automation.Language
|
||||
requiresElevation = true;
|
||||
if (argumentAst != null)
|
||||
{
|
||||
ReportError(parameter.Extent, () => ParserStrings.ParameterCannotHaveArgument, parameter.ParameterName);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(ParserStrings.ParameterCannotHaveArgument),
|
||||
ParserStrings.ParameterCannotHaveArgument,
|
||||
parameter.ParameterName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (argumentAst == null)
|
||||
{
|
||||
ReportError(parameter.Extent, () => ParserStrings.ParameterRequiresArgument, parameter.ParameterName);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(ParserStrings.ParameterRequiresArgument),
|
||||
ParserStrings.ParameterRequiresArgument,
|
||||
parameter.ParameterName);
|
||||
return;
|
||||
}
|
||||
|
||||
object argumentValue;
|
||||
if (!IsConstantValueVisitor.IsConstant(argumentAst, out argumentValue, forRequires: true))
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresArgumentMustBeConstant);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresArgumentMustBeConstant),
|
||||
ParserStrings.RequiresArgumentMustBeConstant);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1755,12 +1787,19 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (requiredShellId != null)
|
||||
{
|
||||
ReportError(parameter.Extent, () => ParameterBinderStrings.ParameterAlreadyBound, null, shellIDToken);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound),
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
null,
|
||||
shellIDToken);
|
||||
return;
|
||||
}
|
||||
if (!(argumentValue is string))
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresInvalidStringArgument, shellIDToken);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresInvalidStringArgument),
|
||||
ParserStrings.RequiresInvalidStringArgument,
|
||||
shellIDToken);
|
||||
return;
|
||||
}
|
||||
requiredShellId = (string)argumentValue;
|
||||
@@ -1769,17 +1808,26 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (!(argumentValue is string))
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresInvalidStringArgument, PSSnapinToken);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresInvalidStringArgument),
|
||||
ParserStrings.RequiresInvalidStringArgument,
|
||||
PSSnapinToken);
|
||||
return;
|
||||
}
|
||||
if (snapinName != null)
|
||||
{
|
||||
ReportError(parameter.Extent, () => ParameterBinderStrings.ParameterAlreadyBound, null, PSSnapinToken);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound),
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
null,
|
||||
PSSnapinToken);
|
||||
return;
|
||||
}
|
||||
if (!PSSnapInInfo.IsPSSnapinIdValid((string)argumentValue))
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => MshSnapInCmdletResources.InvalidPSSnapInName);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(MshSnapInCmdletResources.InvalidPSSnapInName),
|
||||
MshSnapInCmdletResources.InvalidPSSnapInName);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1789,7 +1837,11 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (requiredEditions != null)
|
||||
{
|
||||
ReportError(parameter.Extent, () => ParameterBinderStrings.ParameterAlreadyBound, null, editionToken);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound),
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
null,
|
||||
editionToken);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1811,7 +1863,9 @@ namespace System.Management.Automation.Language
|
||||
var version = Utils.StringToVersion(argumentText);
|
||||
if (version == null)
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresVersionInvalid);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresVersionInvalid),
|
||||
ParserStrings.RequiresVersionInvalid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1819,7 +1873,11 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (snapinVersion != null)
|
||||
{
|
||||
ReportError(parameter.Extent, () => ParameterBinderStrings.ParameterAlreadyBound, null, versionToken);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound),
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
null,
|
||||
versionToken);
|
||||
return;
|
||||
}
|
||||
snapinVersion = version;
|
||||
@@ -1828,7 +1886,11 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (requiredVersion != null && !requiredVersion.Equals(version))
|
||||
{
|
||||
ReportError(parameter.Extent, () => ParameterBinderStrings.ParameterAlreadyBound, null, versionToken);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound),
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
null,
|
||||
versionToken);
|
||||
return;
|
||||
}
|
||||
requiredVersion = version;
|
||||
@@ -1860,12 +1922,18 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
catch (InvalidCastException e)
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresModuleInvalid, e.Message);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresModuleInvalid),
|
||||
ParserStrings.RequiresModuleInvalid,
|
||||
e.Message);
|
||||
return;
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresModuleInvalid, e.Message);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresModuleInvalid),
|
||||
ParserStrings.RequiresModuleInvalid,
|
||||
e.Message);
|
||||
return;
|
||||
}
|
||||
if (requiredModules == null)
|
||||
@@ -1875,7 +1943,9 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportError(parameter.Extent, () => DiscoveryExceptions.ScriptRequiresInvalidFormat);
|
||||
ReportError(parameter.Extent,
|
||||
nameof(DiscoveryExceptions.ScriptRequiresInvalidFormat),
|
||||
DiscoveryExceptions.ScriptRequiresInvalidFormat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1883,7 +1953,10 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (!(arg is string))
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresInvalidStringArgument, assemblyToken);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresInvalidStringArgument),
|
||||
ParserStrings.RequiresInvalidStringArgument,
|
||||
assemblyToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1902,7 +1975,10 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
if (!(arg is string))
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresInvalidStringArgument, editionToken);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresInvalidStringArgument),
|
||||
ParserStrings.RequiresInvalidStringArgument,
|
||||
editionToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1912,7 +1988,10 @@ namespace System.Management.Automation.Language
|
||||
var edition = (string)arg;
|
||||
if (!Utils.IsValidPSEditionValue(edition))
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresPSEditionInvalid, editionToken);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresPSEditionInvalid),
|
||||
ParserStrings.RequiresPSEditionInvalid,
|
||||
editionToken);
|
||||
}
|
||||
|
||||
if (!requiredEditions.Contains(edition, StringComparer.OrdinalIgnoreCase))
|
||||
@@ -1921,7 +2000,10 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportError(argumentAst.Extent, () => ParserStrings.RequiresPSEditionValueIsAlreadySpecified, editionToken);
|
||||
ReportError(argumentAst.Extent,
|
||||
nameof(ParserStrings.RequiresPSEditionValueIsAlreadySpecified),
|
||||
ParserStrings.RequiresPSEditionValueIsAlreadySpecified,
|
||||
editionToken);
|
||||
}
|
||||
}
|
||||
return requiredEditions;
|
||||
@@ -1994,7 +2076,10 @@ namespace System.Management.Automation.Language
|
||||
{
|
||||
// error - reached end of input without seeing terminator
|
||||
UngetChar();
|
||||
ReportIncompleteInput(errorIndex, () => ParserStrings.TerminatorExpectedAtEndOfString, "'");
|
||||
ReportIncompleteInput(errorIndex,
|
||||
nameof(ParserStrings.TerminatorExpectedAtEndOfString),
|
||||
ParserStrings.TerminatorExpectedAtEndOfString,
|
||||
"'");
|
||||
flags = TokenFlags.TokenInError;
|
||||
}
|
||||
|
||||
@@ -2059,7 +2144,9 @@ namespace System.Management.Automation.Language
|
||||
goto default;
|
||||
|
||||
UngetChar();
|
||||
ReportIncompleteInput(_tokenStart, () => ParserStrings.IncompleteDollarSubexpressionReference);
|
||||
ReportIncompleteInput(_tokenStart,
|
||||
nameof(ParserStrings.IncompleteDollarSubexpressionReference),
|
||||
ParserStrings.IncompleteDollarSubexpressionReference);
|
||||
flags = TokenFlags.TokenInError;
|
||||
scanning = false;
|
||||
break;
|
||||
@@ -2147,7 +2234,10 @@ namespace System.Management.Automation.Language
|
||||
if (c == '\0')
|
||||
{
|
||||
UngetChar();
|
||||
ReportIncompleteInput(errorIndex, () => ParserStrings.TerminatorExpectedAtEndOfString, "\"");
|
||||
ReportIncompleteInput(errorIndex,
|
||||
nameof(ParserStrings.TerminatorExpectedAtEndOfString),
|
||||
ParserStrings.TerminatorExpectedAtEndOfString,
|
||||
"\"");
|
||||
flags = TokenFlags.TokenInError;
|
||||
}
|
||||
|
||||
@@ -2235,7 +2325,10 @@ namespace System.Management.Automation.Language
|
||||
if (c == '\0' && AtEof())
|
||||
{
|
||||
UngetChar();
|
||||
ReportIncompleteInput(headerOffset, () => ParserStrings.TerminatorExpectedAtEndOfString, string.Concat(header[1], '@'));
|
||||
ReportIncompleteInput(headerOffset,
|
||||
nameof(ParserStrings.TerminatorExpectedAtEndOfString),
|
||||
ParserStrings.TerminatorExpectedAtEndOfString,
|
||||
string.Concat(header[1], '@'));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2245,7 +2338,9 @@ namespace System.Management.Automation.Language
|
||||
// scanning at the end of the line. Don't skip the newline so we have a newline to terminate the current
|
||||
// expression.
|
||||
|
||||
ReportError(_currentIndex, () => ParserStrings.UnexpectedCharactersAfterHereStringHeader);
|
||||
ReportError(_currentIndex,
|
||||
nameof(ParserStrings.UnexpectedCharactersAfterHereStringHeader),
|
||||
ParserStrings.UnexpectedCharactersAfterHereStringHeader);
|
||||
|
||||
do
|
||||
{
|
||||
@@ -2363,11 +2458,16 @@ namespace System.Management.Automation.Language
|
||||
UngetChar();
|
||||
if (falseFooterOffset != -1)
|
||||
{
|
||||
ReportIncompleteInput(falseFooterOffset, () => ParserStrings.WhitespaceBeforeHereStringFooter);
|
||||
ReportIncompleteInput(falseFooterOffset,
|
||||
nameof(ParserStrings.WhitespaceBeforeHereStringFooter),
|
||||
ParserStrings.WhitespaceBeforeHereStringFooter);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportIncompleteInput(headerOffset, () => ParserStrings.TerminatorExpectedAtEndOfString, "'@");
|
||||
ReportIncompleteInput(headerOffset,
|
||||
nameof(ParserStrings.TerminatorExpectedAtEndOfString),
|
||||
ParserStrings.TerminatorExpectedAtEndOfString,
|
||||
"'@");
|
||||
}
|
||||
flags = TokenFlags.TokenInError;
|
||||
break;
|
||||
@@ -2465,11 +2565,16 @@ namespace System.Management.Automation.Language
|
||||
UngetChar();
|
||||
if (falseFooterOffset != -1)
|
||||
{
|
||||
ReportIncompleteInput(falseFooterOffset, () => ParserStrings.WhitespaceBeforeHereStringFooter);
|
||||
ReportIncompleteInput(falseFooterOffset,
|
||||
nameof(ParserStrings.WhitespaceBeforeHereStringFooter),
|
||||
ParserStrings.WhitespaceBeforeHereStringFooter);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReportIncompleteInput(headerOffset, () => ParserStrings.TerminatorExpectedAtEndOfString, "\"@");
|
||||
ReportIncompleteInput(headerOffset,
|
||||
nameof(ParserStrings.TerminatorExpectedAtEndOfString),
|
||||
ParserStrings.TerminatorExpectedAtEndOfString,
|
||||
"\"@");
|
||||
}
|
||||
flags = TokenFlags.TokenInError;
|
||||
break;
|
||||
@@ -2545,7 +2650,9 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
break;
|
||||
case '{':
|
||||
ReportError(_currentIndex, () => ParserStrings.OpenBraceNeedsToBeBackTickedInVariableName);
|
||||
ReportError(_currentIndex,
|
||||
nameof(ParserStrings.OpenBraceNeedsToBeBackTickedInVariableName),
|
||||
ParserStrings.OpenBraceNeedsToBeBackTickedInVariableName);
|
||||
break;
|
||||
case '\0':
|
||||
if (AtEof())
|
||||
@@ -2564,13 +2671,17 @@ namespace System.Management.Automation.Language
|
||||
string name = GetStringAndRelease(sb);
|
||||
if (c != '}')
|
||||
{
|
||||
ReportIncompleteInput(errorStartPosition, () => ParserStrings.IncompleteDollarVariableReference);
|
||||
ReportIncompleteInput(errorStartPosition,
|
||||
nameof(ParserStrings.IncompleteDollarVariableReference),
|
||||
ParserStrings.IncompleteDollarVariableReference);
|
||||
}
|
||||
if (name.Length == 0)
|
||||
{
|
||||
if (c == '}')
|
||||
{
|
||||
ReportError(_currentIndex - 1, () => ParserStrings.EmptyVariableReference);
|
||||
ReportError(_currentIndex - 1,
|
||||
nameof(ParserStrings.EmptyVariableReference),
|
||||
ParserStrings.EmptyVariableReference);
|
||||
}
|
||||
name = ":Error:";
|
||||
}
|
||||
@@ -2598,7 +2709,9 @@ namespace System.Management.Automation.Language
|
||||
//{
|
||||
// return NewToken(TokenKind.Unknown);
|
||||
//}
|
||||
ReportError(NewScriptExtent(_tokenStart, _currentIndex), () => ParserStrings.InvalidBracedVariableReference);
|
||||
ReportError(NewScriptExtent(_tokenStart, _currentIndex),
|
||||
nameof(ParserStrings.InvalidBracedVariableReference),
|
||||
ParserStrings.InvalidBracedVariableReference);
|
||||
}
|
||||
|
||||
return NewVariableToken(path, false);
|
||||
@@ -2758,16 +2871,19 @@ namespace System.Management.Automation.Language
|
||||
path = new VariablePath(GetStringAndRelease(sb));
|
||||
if (string.IsNullOrEmpty(path.UnqualifiedPath))
|
||||
{
|
||||
Expression<Func<string>> msg;
|
||||
string errorId;
|
||||
string errorMsg;
|
||||
if (path.IsDriveQualified)
|
||||
{
|
||||
msg = () => ParserStrings.InvalidVariableReferenceWithDrive;
|
||||
errorId = nameof(ParserStrings.InvalidVariableReferenceWithDrive);
|
||||
errorMsg = ParserStrings.InvalidVariableReferenceWithDrive;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = () => ParserStrings.InvalidVariableReference;
|
||||
errorId = nameof(ParserStrings.InvalidVariableReference);
|
||||
errorMsg = ParserStrings.InvalidVariableReference;
|
||||
}
|
||||
ReportError(NewScriptExtent(_tokenStart, _currentIndex), msg);
|
||||
ReportError(NewScriptExtent(_tokenStart, _currentIndex), errorId, errorMsg);
|
||||
}
|
||||
|
||||
return NewVariableToken(path, splatted);
|
||||
@@ -3285,7 +3401,10 @@ namespace System.Management.Automation.Language
|
||||
return ScanGenericToken(GetStringBuilder());
|
||||
}
|
||||
|
||||
ReportError(_currentIndex, () => ParserStrings.BadNumericConstant, _script.Substring(_tokenStart, _currentIndex - _tokenStart));
|
||||
ReportError(_currentIndex,
|
||||
nameof(ParserStrings.BadNumericConstant),
|
||||
ParserStrings.BadNumericConstant,
|
||||
_script.Substring(_tokenStart, _currentIndex - _tokenStart));
|
||||
}
|
||||
|
||||
return NewNumberToken(value);
|
||||
@@ -3895,7 +4014,9 @@ namespace System.Management.Automation.Language
|
||||
return ScanVariable(true, false);
|
||||
}
|
||||
|
||||
ReportError(_currentIndex - 1, () => ParserStrings.UnrecognizedToken);
|
||||
ReportError(_currentIndex - 1,
|
||||
nameof(ParserStrings.UnrecognizedToken),
|
||||
ParserStrings.UnrecognizedToken);
|
||||
return NewToken(TokenKind.Unknown);
|
||||
|
||||
case '#':
|
||||
@@ -3922,7 +4043,9 @@ namespace System.Management.Automation.Language
|
||||
}
|
||||
if (c1 == '\0' && AtEof())
|
||||
{
|
||||
ReportIncompleteInput(_currentIndex, () => ParserStrings.IncompleteString);
|
||||
ReportIncompleteInput(_currentIndex,
|
||||
nameof(ParserStrings.IncompleteString),
|
||||
ParserStrings.IncompleteString);
|
||||
|
||||
// Unget the EOF so we can return an EOF token.
|
||||
UngetChar();
|
||||
|
||||
@@ -755,7 +755,9 @@ namespace System.Management.Automation
|
||||
if (HasBeginBlock || HasProcessBlock || ast.Body.ParamBlock != null)
|
||||
{
|
||||
Ast errorAst = ast.Body.BeginBlock ?? (Ast)ast.Body.ProcessBlock ?? ast.Body.ParamBlock;
|
||||
parser.ReportError(errorAst.Extent, () => ParserStrings.InvalidScriptBlockInDataSection);
|
||||
parser.ReportError(errorAst.Extent,
|
||||
nameof(ParserStrings.InvalidScriptBlockInDataSection),
|
||||
ParserStrings.InvalidScriptBlockInDataSection);
|
||||
}
|
||||
|
||||
if (HasEndBlock)
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace System.Management.Automation
|
||||
null,
|
||||
null,
|
||||
ParameterBinderStrings.ParameterAlreadyBound,
|
||||
"ParameterAlreadyBound");
|
||||
nameof(ParameterBinderStrings.ParameterAlreadyBound));
|
||||
|
||||
throw bindingException;
|
||||
}
|
||||
|
||||
@@ -1461,4 +1461,7 @@ ModuleVersion : Version of module to import. If used, ModuleName must represent
|
||||
<data name="PsDscRunAsCredentialMergeErrorForCompositeResources" xml:space="preserve">
|
||||
<value>Conflict in using PsDscRunAsCredential for Resource {0} because it already specifies PsDscRunAsCredential value. We can only use one PsDscRunAsCredential for the composite resource. </value>
|
||||
</data>
|
||||
<data name="ParserError" xml:space="preserve">
|
||||
<value>{0}</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -453,7 +453,7 @@ namespace System.Management.Automation
|
||||
// argument exception
|
||||
if (!IsPSSnapinIdValid(psSnapinId))
|
||||
{
|
||||
throw PSTraceSource.NewArgumentException("mshSnapInId",
|
||||
throw PSTraceSource.NewArgumentException(nameof(psSnapinId),
|
||||
MshSnapInCmdletResources.InvalidPSSnapInName,
|
||||
psSnapinId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user