pseudo
pseudo
CC#
Created by pseudo on 10/18/2024 in #help
Any case where `TError` can't be boxed in example?
So I have the following:
public class ParseResult<TResult, TError>
{
private readonly TResult? _result;
private readonly TError? _error;

private ParseResult(TResult? result, TError? error)
{
_result = result;
_error = error;
}

public static ParseResult<TResult, TError> CreatedResult(TResult result)
=> new ParseResult<TResult, TError>(result, null);
}
public class ParseResult<TResult, TError>
{
private readonly TResult? _result;
private readonly TError? _error;

private ParseResult(TResult? result, TError? error)
{
_result = result;
_error = error;
}

public static ParseResult<TResult, TError> CreatedResult(TResult result)
=> new ParseResult<TResult, TError>(result, null);
}
But am getting an error on last line passing null in, I can see it resolves if i add a class constraint to the generic arg, or if i give default, but confused why it cant infer that TError? is always gonna be boxed, i.e. if i had int as TError surely it can work out Nullable<int> from TError?
15 replies