Skip to content

Commit

Permalink
Fix ValidateSet with generator in a module (#5702)
Browse files Browse the repository at this point in the history
The symbol resolver was properly resolving the type to the class
definition, but that resolution was ignored at runtime because we used
the string instead of the ITypeName - the ITypeName kept the reference
to the class definition.

Fix #5661
  • Loading branch information
lzybkr authored and iSazonov committed Jan 9, 2018
1 parent 0d893a5 commit 8bd5378
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/System.Management.Automation/engine/parser/Compiler.cs
Expand Up @@ -1309,14 +1309,16 @@ private static Attribute NewValidateSetAttribute(AttributeAst ast)
// 'ValidateSet([CustomGeneratorType], IgnoreCase=$false)' is supported in scripts.
if (ast.PositionalArguments.Count == 1 && ast.PositionalArguments[0] is TypeExpressionAst generatorTypeAst)
{
if (TypeResolver.TryResolveType(generatorTypeAst.TypeName.FullName, out Type generatorType))
var generatorType = TypeResolver.ResolveITypeName(generatorTypeAst.TypeName, out Exception exception);
if (generatorType != null)
{
result = new ValidateSetAttribute(generatorType);
}
else
{
throw InterpreterError.NewInterpreterException(ast, typeof(RuntimeException), ast.Extent,
"TypeNotFound", ParserStrings.TypeNotFound, generatorTypeAst.TypeName.FullName, typeof(System.Management.Automation.IValidateSetValuesGenerator).FullName);
throw InterpreterError.NewInterpreterExceptionWithInnerException(
ast, typeof(RuntimeException), ast.Extent, "TypeNotFound", ParserStrings.TypeNotFound, exception,
generatorTypeAst.TypeName.FullName, typeof(System.Management.Automation.IValidateSetValuesGenerator).FullName);
}
}
else
Expand Down

0 comments on commit 8bd5378

Please sign in to comment.