Skip to content

Commit 37283a2

Browse files
committed
add null checks to constructors to ensure valid data
1 parent b8a762e commit 37283a2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/CommandLine/ParserResult.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ public abstract class ParserResult<T>
6868
internal ParserResult(IEnumerable<Error> errors, TypeInfo typeInfo)
6969
{
7070
this.tag = ParserResultType.NotParsed;
71-
this.typeInfo = typeInfo;
72-
Errors = errors;
71+
this.typeInfo = typeInfo ?? TypeInfo.Create(typeof(T));
72+
Errors = errors ?? new Error[0];
7373
Value = default;
7474
}
7575

7676
internal ParserResult(T value, TypeInfo typeInfo)
7777
{
78+
Value = value ?? throw new ArgumentNullException(nameof(value));
7879
this.tag = ParserResultType.Parsed;
79-
this.typeInfo = typeInfo;
80+
this.typeInfo = typeInfo ?? TypeInfo.Create(value?.GetType() ?? typeof(T));
8081
Errors = new Error[0];
81-
Value = value;
8282
}
8383

8484
/// <summary>

0 commit comments

Comments
 (0)