Support default value for structs, such as default(CancellationToken)
bnuzhouwei opened this issue · comments
Runtime: NET6.0
IronPython: 2.7.11
In mongodb, there are many methods with default value as default(CancellationToken)
long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
but in IronPython, when we call the method:
CountDocuments[BsonDocument]("collection")
got
IronPython.Runtime.Exceptions.TypeErrorException: expected CancellationToken, got NoneType
I seems that IronPython does't support default value for structs, such as default(CancellationToken)
Thanks for the report, I managed to reproduce this with something like:
public void Test(CancellationToken token = default);
A potential fix would be to add some sort of check to DefaultArgBuilder.ToExpression
in the DLR (don't think this is correct but something similar may work):
if (parameterType.IsValueType) {
// default(T)
return AstUtils.Constant(Activator.CreateInstance(parameterType));
}
Thanks, can we do this without modified the IronPython Souce Code?
DefaultArgBuilder.ToExpression
Thanks, can we do this without modified the IronPython Souce Code?
I don't have any workaround, I think you will have to explicitly pass in the argument CountDocuments[BsonDocument]("collection", cancellationToken=CancellationToken.None)
.