Closed rmathias86 closed 6 years ago
Hi there.
I think that the code should work as-is with dart2. In fact, I just tried running the test suite against 2.0.0-dev.60.0
and all tests seem to pass. Let me know if you encounter any issues using dart 2.x
Hey,
compiler message: file:///Users/rodrigomathias/development/flutter/.pub-cache/git/dart_amqp-7a2c7fd2278dfabf4138fb196de5312d1ebcfc80/lib/src/client/impl/channel_impl.dart:417:10: Error: The return type of the method '_ChannelImpl::close' is dart.async::Future<dynamic>, which does not match the return type of the overridden method (dart.async::Future<dart_amqp.client::Channel>). compiler message: Change to a subtype of dart.async::Future<dart_amqp.client::Channel>. compiler message: Future close() => _close(replyCode : ErrorType.SUCCESS, replyText : "Normal shutdown"); compiler message: ^ compiler message: file:///Users/rodrigomathias/development/flutter/.pub-cache/git/dart_amqp-7a2c7fd2278dfabf4138fb196de5312d1ebcfc80/lib/src/client/channel.dart:11:19: Context: This is the overriden method ('close'). compiler message: Future<Channel> close(); compiler message: ^
`type 'Future
`
ConnectionSettings settings = new ConnectionSettings( host : "baboon.rmq.cloudamqp.com", virtualHost: "lahubkks", authProvider: new AmqPlainAuthenticator("lahubkks","nroDZ6yuho7zgQNRnCxe5r1PzxfW2XEG") ); Client client = new Client(settings: settings); client .channel() .then((Channel channel) => channel.queue("hello")) .then((Queue queue) => queue.consume()) .then((Consumer consumer) => consumer.listen((AmqpMessage message) { print(" [x] Received string: ${message.payloadAsString}"); }));
flutter run --no-preview-dart-2
(to not use dart 2 in flutter) it works perfectly.Thanks in advanced for any idea what's going on.
I've found this thread regarding --preview-dart-2 https://groups.google.com/a/dartlang.org/forum/#!topic/announce/D2mju9oXmUg
This may cause some breakages due to stricter Dart type enforcement.
Thanks for bringing this to my attention. I think I know why the compiler complains. I will run everything through dartalyzer and push an updated package later today.
In the meantime you can try applying this fix manually to your local package:
diff --git a/lib/src/client/impl/channel_impl.dart b/lib/src/client/impl/channel_impl.dart
index 9686c1f..f9b4c47 100644
--- a/lib/src/client/impl/channel_impl.dart
+++ b/lib/src/client/impl/channel_impl.dart
@@ -410,11 +410,11 @@ class _ChannelImpl implements Channel {
}
/**
- * Close the channel and return a [Future] to be completed when the channel is closed.
+ * Close the channel and return a [Future<Channel>] to be completed when the channel is closed.
*
* After closing the channel any attempt to send a message over it will cause a [StateError]
*/
- Future close() => _close(replyCode : ErrorType.SUCCESS, replyText : "Normal shutdown");
+ Future<Channel> close() => _close(replyCode : ErrorType.SUCCESS, replyText : "Normal shutdown");
@achilleasa, thanks for your efforts
I ran dartanalyzer command with --no-implicit-casts
(flutter uses strong mode) and got these errors now
error • A value of type 'Consumer' can't be assigned to a variable of type '_ConsumerImpl' at lib/src/client/impl/channel_impl.dart:264:50 • invalid_assignment error • The argument type 'DecodedMessage' can't be assigned to the parameter type 'DecodedMessageImpl' at lib/src/client/impl/channel_impl.dart:287:26 • argument_type_not_assignable error • The return type 'Future' isn't a 'Future
', as defined by the method 'queue' at lib/src/client/impl/channel_impl.dart:432:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'privateQueue' at lib/src/client/impl/channel_impl.dart:448:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'exchange' at lib/src/client/impl/channel_impl.dart:471:12 • return_of_invalid_type error • The return type 'StreamSubscription' isn't a 'StreamSubscription ', as defined by the method 'basicReturnListener' at lib/src/client/impl/channel_impl.dart:474:162 • return_of_invalid_type error • The argument type '(BasicReturnMessage) → void' can't be assigned to the parameter type '(dynamic) → void' at lib/src/client/impl/channel_impl.dart:474:195 • argument_type_not_assignable error • The return type 'Future' isn't a 'Future ', as defined by the method 'qos' at lib/src/client/impl/channel_impl.dart:490:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'select' at lib/src/client/impl/channel_impl.dart:505:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'commit' at lib/src/client/impl/channel_impl.dart:512:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'rollback' at lib/src/client/impl/channel_impl.dart:519:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'flow' at lib/src/client/impl/channel_impl.dart:528:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'recover' at lib/src/client/impl/channel_impl.dart:537:12 • return_of_invalid_type error • Type 'dynamic' of the switch expression isn't assignable to the type 'Type' of case expressions at lib/src/client/impl/client_impl.dart:176:13 • switch_expression_not_assignable error • The return type 'StreamSubscription' isn't a 'StreamSubscription ', as defined by the method 'errorListener' at lib/src/client/impl/client_impl.dart:282:136 • return_of_invalid_type error • The argument type '(Exception) → void' can't be assigned to the parameter type '(dynamic) → void' at lib/src/client/impl/client_impl.dart:282:157 • argument_type_not_assignable error • The return type 'StreamSubscription' isn't a 'StreamSubscription ', as defined by the method 'listen' at lib/src/client/impl/consumer_impl.dart:13:133 • return_of_invalid_type error • The argument type '(AmqpMessage) → void' can't be assigned to the parameter type '(dynamic) → void' at lib/src/client/impl/consumer_impl.dart:13:159 • argument_type_not_assignable error • The return type 'Future' isn't a 'Future ', as defined by the method 'cancel' at lib/src/client/impl/consumer_impl.dart:23:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'delete' at lib/src/client/impl/exchange_impl.dart:21:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'delete' at lib/src/client/impl/queue_impl.dart:27:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'purge' at lib/src/client/impl/queue_impl.dart:38:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'bind' at lib/src/client/impl/queue_impl.dart:63:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'unbind' at lib/src/client/impl/queue_impl.dart:87:12 • return_of_invalid_type error • The return type 'Future' isn't a 'Future ', as defined by the method 'consume' at lib/src/client/impl/queue_impl.dart:119:12 • return_of_invalid_type error • The return type 'dynamic' isn't a 'Map', as defined by the method 'payloadAsJson' at lib/src/protocol/frame/impl/decoded_message_impl.dart:52:12 • return_of_invalid_type error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:19:42 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:26:41 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:33:42 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:40:41 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:47:42 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:54:41 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:61:46 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_decoder.dart:68:46 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:23:54 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:29:54 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:35:54 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:47:55 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:53:55 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:59:55 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:65:56 • argument_type_not_assignable error • The argument type 'Endianness' can't be assigned to the parameter type 'Endian' at lib/src/protocol/stream/type_encoder.dart:71:56 • argument_type_not_assignable error • The argument type 'List ' can't be assigned to the parameter type 'Uint8List' at lib/src/protocol/stream/type_encoder.dart:108:21 • argument_type_not_assignable error • The argument type 'List ' can't be assigned to the parameter type 'Uint8List' at lib/src/protocol/stream/type_encoder.dart:121:21 • argument_type_not_assignable error • The argument type 'Map' can't be assigned to the parameter type 'Map<String, Object>' at lib/src/protocol/stream/type_encoder.dart:174:23 • argument_type_not_as
Hey,
I made some changes on my forked repo and it's working nicely, for now. https://github.com/rmathias86/dart_amqp/commit/6fa0acb8a0b1e4210f8fe54ecfe70c8733d5eb2d#diff-9108cd2274bb34b410042e7c8bebae1d
Ah, thanks for figuring out a fix. I totally missed that as I am not currently using Flutter. Are your changes (Endian, JSON and UTF8) backwards compatible with dart 1.x?
Actually, I could merge #14 which has some dartanalyzer fixes (and also updates .travis.yaml to run dartanalyzer) and you can open a new PR with your additional fixes (also update .travis.yaml to run with --no-implicit-casts
).
@Hi @achilleasa,
So, I didn't test with dart 1.x yet. Even dart-analyzer was complaining about Endian, JSON and UTF8, I think these changes are not necessary, actually. I will test it again using only < TYPE > changes., which I believe should be backward compatible with dart 1.x, right?
I just merged #14 which fixes the type errors reported by dartanalyzer (but not the ones reported when running with --no-implicit-casts
). As I mention above, I have updated the .travis.yaml
file to run tests/dartanalyzer against both dart 1.x and 2.x so if you rebase your extra type changes on top of HEAD and add the --no-implicit-casts
flag to dartanalyzer the CI should check if everything is backwards compatible with dart 1.
@hey @achilleasa,
I can confirm with the #15 that only these changes are enough to run dart_amqp with current flutter SDK, either using beta or master channel. I don't have enough experience with the dart language to decide what is better about other changes. 👍
Many thanks, this plugin is going to be a key to achieve the success of our project in our company.
I have merged #15 and pushed an updated package so I am closing this issue.
Thanks for your PR and please do open more issues if you encounter other dart2 compatibility issues in the future.
Hey there,
Are there any expectations to convert the code for dart2? Or to have a specific branch of it. I've tested it with Flutter (Dart 1) and RabbitMQ and it's working nicely. But I do think to use dart2 instead.
I would like to help if possible.
Cheers,