Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/parser/ast.cs (C#)

Code before:
        public TypeName(IScriptExtent extent, string name, string assembly)
            : this(extent, name)
        {
            if (string.IsNullOrEmpty(assembly))
            {
                throw PSTraceSource.NewArgumentNullException(nameof(assembly));
            }

            AssemblyName = assembly;
        }

        /// <summary>
        /// Construct a typename that represents a generic type definition.
        /// </summary>
        /// <param name="extent">The extent of the typename.</param>
        /// <param name="name">The name of the type.</param>
        /// <param name="genericArgumentCount">The number of generic arguments.</param>
        internal TypeName(IScriptExtent extent, string name, int genericArgumentCount)
            : this(extent, name)
        {
            if (genericArgumentCount > 0 && !_name.Contains('`'))
            {
                _genericArgumentCount = genericArgumentCount;
            }
        }

        /// <summary>
        /// Returns the full name of the type.
        /// </summary>
        public string FullName { get { return AssemblyName != null ? _name + "," + AssemblyName : _name; } }

        /// <summary>
        /// Returns the name of the type, w/o any assembly name if one was specified.
        /// </summary>
        public string Name { get { return _name; } }

        /// <summary>
        /// The name of the assembly, if specified, otherwise null.
        /// </summary>
        public string AssemblyName { get; internal set; }

        /// <summary>
        /// Always returns false, array typenames are instances of <see cref="ArrayTypeName"/>.
        /// </summary>
        public bool IsArray { get { return false; } }

        /// <summary>
        /// Always returns false, generic typenames are instances of <see cref="GenericTypeName"/>.
        /// </summary>
        public bool IsGeneric { get { return false; } }


Review comment (suggestion):
Usually, we expect a constructor to throw an exception if the argument is unexpected. But here we perform a correction of the argument. It's amazing. I'm afraid this may provoke accidental misuse of this constructor in the future. At the very least, it would be good to add a comment with examples of the scenarios we address and explaining why this correction is needed in this place.  
Alternatively, we could perform a check at the call location and pass the correct arguments.
It could be even better to use a template like `private static TypeName TypeName.CreateAlternativeGenericTypeName()` with a comprehensive description.

Code after:
        public TypeName(IScriptExtent extent, string name, string assembly)
            : this(extent, name)
        {
            if (string.IsNullOrEmpty(assembly))
            {
                throw PSTraceSource.NewArgumentNullException(nameof(assembly));
            }

            AssemblyName = assembly;
        }

        /// <summary>
        /// Construct a typename that represents a generic type definition.
        /// </summary>
        /// <param name="extent">The extent of the typename.</param>
        /// <param name="name">The name of the type.</param>
        /// <param name="genericArgumentCount">The number of generic arguments.</param>
        internal TypeName(IScriptExtent extent, string name, int genericArgumentCount)
            : this(extent, name)
        {
            ArgumentOutOfRangeException.ThrowIfLessThan(genericArgumentCount, 0);

            if (genericArgumentCount > 0 && !_name.Contains('`'))
            {
                _genericArgumentCount = genericArgumentCount;
            }
        }

        /// <summary>
        /// Returns the full name of the type.
        /// </summary>
        public string FullName { get { return AssemblyName != null ? _name + "," + AssemblyName : _name; } }

        /// <summary>
        /// Returns the name of the type, w/o any assembly name if one was specified.
        /// </summary>
        public string Name { get { return _name; } }

        /// <summary>
        /// The name of the assembly, if specified, otherwise null.
        /// </summary>
        public string AssemblyName { get; internal set; }

        /// <summary>
        /// Always returns false, array typenames are instances of <see cref="ArrayTypeName"/>.
        /// </summary>
        public bool IsArray { get { return false; } }

        /// <summary>
        /// Always returns false, generic typenames are instances of <see cref="GenericTypeName"/>.
        /// </summary>