Skip to content

Commit 3094bfb

Browse files
committed
add null checks to constructors to ensure valid data
1 parent ad50269 commit 3094bfb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/CommandLine/ParserResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ public abstract class ParserResult<T>
6767
internal ParserResult(IEnumerable<Error> errors, TypeInfo typeInfo)
6868
{
6969
this.tag = ParserResultType.NotParsed;
70-
this.typeInfo = typeInfo;
71-
Errors = errors;
70+
this.typeInfo = typeInfo ?? TypeInfo.Create(typeof(T));
71+
Errors = errors ?? new Error[0];
7272
Value = default;
7373
}
7474

7575
internal ParserResult(T value, TypeInfo typeInfo)
7676
{
77+
Value = value ?? throw new ArgumentNullException(nameof(value));
7778
this.tag = ParserResultType.Parsed;
78-
this.typeInfo = typeInfo;
79+
this.typeInfo = typeInfo ?? TypeInfo.Create(value.GetType());
7980
Errors = new Error[0];
80-
Value = value;
8181
}
8282

8383
/// <summary>

0 commit comments

Comments
 (0)