Skip to content

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

Merged
merged 3 commits into from
Dec 27, 2023

Conversation

natebosch
Copy link
Member

@natebosch natebosch commented Jun 29, 2023

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.

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.
@natebosch natebosch requested a review from srawlins June 29, 2023 19:02
@natebosch
Copy link
Member Author

This wouldn't catch cases where the type variable is bound to Set... so maybe it's better to just remove it after all?

cc @lrhn WDYT?

@@ -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'),
Copy link
Member

@lrhn lrhn Jun 29, 2023

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>.

Copy link
Member

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.

@natebosch natebosch changed the title Invert a type test on a type variable Remove a non-useful type check on generic type variable Dec 27, 2023
Copy link
Member

@srawlins srawlins left a 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!

@srawlins srawlins merged commit de06294 into main Dec 27, 2023
@srawlins srawlins deleted the type-variable-type-test branch December 27, 2023 22:18
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.

3 participants