Skip to content

Conversation

@jonsequitur
Copy link
Contributor

This fixes #2210. The issue was that bool parsing had a special case in place so that it doesn't consume the following token if that token can't be parsed as a bool. This lets the unparseable token by consumed by a different symbol, which is typically the intent.

The fix includes bool? in that special case.

@jonsequitur jonsequitur marked this pull request as ready for review June 7, 2023 22:22
@jonsequitur jonsequitur requested review from Keboo and adamsitnik June 7, 2023 22:22
@jonsequitur jonsequitur merged commit 02fe27c into dotnet:main Jun 7, 2023
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing the bug!


if (validatedResult.Result == ArgumentConversionResultType.Successful
&& convertedResult.Result == ArgumentConversionResultType.NoArgument)
if (validatedResult is { Result: ArgumentConversionResultType.Successful }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you find this syntax more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer it as a best practice because the behavior of == can be changed by operator overloading.

}
}
else if (argument.ValueType == typeof(bool) &&
else if ((argument.ValueType == typeof(bool) || argument.ValueType == typeof(bool?)) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

BTW a while ago I have introduced a helper method for that:

internal bool IsBoolean() => ValueType == typeof(bool) || ValueType == typeof(bool?);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out! I've updated to use that in my other PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option with nullable type causes InvalidOperationException when parsing invalid value

3 participants