-
Notifications
You must be signed in to change notification settings - Fork 125
Remove a non-useful type check on generic type variable #3457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This type test was introduced during the null safety migration and I do not see discussion about the intention. In practice this is `assert(true)` so it would be safest to remove it entirely, but we can also take a guess at the intention. The full assert when it was introduced was `asset(T is! Iterable || splitCommas == true)`. Later the second condition was removed, and the `splitCommas` field overridden to always return `false`. I think the intention was to express that options which support multiple values _must_ split commas, and now that this class is only used without splitting commas the intention is that the options must be scalar values. Invert the type test with a value known to satisfy a check for any subtype of `Iterable`. Add a string explaining the assert.
This wouldn't catch cases where the type variable is bound to cc @lrhn WDYT? |
lib/src/dartdoc_options.dart
Outdated
@@ -597,7 +597,8 @@ class DartdocOptionArgSynth<T> extends DartdocOption<T> | |||
String help = '', | |||
OptionKind optionIs = OptionKind.other, | |||
this.negatable = false}) | |||
: assert(T is! Iterable), | |||
: assert(const <Never>[] is! T, | |||
'$T should not be bound to a type which allows iterables'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would indeed allow T
to be Set
, which is iterable.
To check whether T
is/is not a subtype of Iterable
, you need to put T
on the LHS of the is
check, e.g., <T>[] is! List<Iterable>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But... the comment says to not allow any type which allows an iterable. That suggests not allowingObject
either.
In practice any non-final type may allow an iterable, so I wouldn't try to do anything for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, thanks!
This type test was introduced during the null safety migration and I do
not see discussion about the intention.
In practice this is
assert(true)
so it is safe to remove.I think the intention was to express that options which support multiple
values must split commas, and now that this class is only used without
splitting commas the intention is that the options must be scalar
values.
It is not easy to perform this type of test on a type variable, so remove it.