Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Invalid override errors from reasonable (?) code in pkg/convert #360

Closed
kevmoo opened this issue Oct 8, 2015 · 3 comments
Closed

Invalid override errors from reasonable (?) code in pkg/convert #360

kevmoo opened this issue Oct 8, 2015 · 3 comments

Comments

@kevmoo
Copy link
Contributor

kevmoo commented Oct 8, 2015

From: https://github.com/dart-lang/convert

with dartanalyzer --strong lib/convert.dart

[error] Invalid override. The type of HexDecoder.startChunkedConversion ((Sink<List<int>>) → StringConversionSink) is not a subtype of Converter<String, List<int>>.startChunkedConversion ((Sink<dynamic>) → ChunkedConversionSink<dynamic>). (/Users/kevmoo/source/github/convert/lib/src/hex/decoder.dart, line 34, col 3)
[error] Invalid override. The type of HexEncoder.startChunkedConversion ((Sink<String>) → ByteConversionSink) is not a subtype of Converter<List<int>, String>.startChunkedConversion ((Sink<dynamic>) → ChunkedConversionSink<dynamic>). (/Users/kevmoo/source/github/convert/lib/src/hex/encoder.dart, line 24, col 3)
[error] Invalid override. The type of PercentDecoder.startChunkedConversion ((Sink<List<int>>) → StringConversionSink) is not a subtype of Converter<String, List<int>>.startChunkedConversion ((Sink<dynamic>) → ChunkedConversionSink<dynamic>). (/Users/kevmoo/source/github/convert/lib/src/percent/decoder.dart, line 44, col 3)
[error] Invalid override. The type of PercentEncoder.startChunkedConversion ((Sink<String>) → ByteConversionSink) is not a subtype of Converter<List<int>, String>.startChunkedConversion ((Sink<dynamic>) → ChunkedConversionSink<dynamic>). (/Users/kevmoo/source/github/convert/lib/src/percent/encoder.dart, line 27, col 3)
@leafpetersen
Copy link
Contributor

I think this is right, at least given our current co-variant generics. We should be producing better error messages, but the first error message is basically telling you that (Sink<List<int>>) → StringConversionSink is not a subtype of (Sink<dynamic>) → ChunkedConversionSink<dynamic>, which is true (since if you pass a function expectsASinkOfListOfInt which expects to be called with a Sink<List<int>> to a context expecting something which can be called with any Sink<dynamic>, then expectsASinkOfListOfInt might get called with a Sink<String>, and hijinks might ensue.

If Sink is in fact contra-variant in its type parameter, then this could be reasonable - is it? I've been wondering whether we should add annotation based support for type parameter variance at some point - would that be the right resolution for this?

@jmesserly
Copy link
Contributor

@leafpetersen Sink is indeed contravariant:
https://api.dartlang.org/1.12.1/dart-core/Sink-class.html

This is similar to our issue with Equality.

Not sure anyone's hit it yet, but Comparable/Comparator are similar.

Co/contravariance annotations 👍

@jmesserly
Copy link
Contributor

merging the error UX into this SDK bug:
dart-lang/sdk#24753

also this bug discusses merging CodeChecker and ErrorVerifier, which will really help these messages:
dart-lang/sdk#25350

contravariant request is currently tracked at
#324

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

No branches or pull requests

4 participants