dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.21k stars 1.57k forks source link

Compiler crash: Iterables do not have same length #53453

Closed burekas7 closed 1 year ago

burekas7 commented 1 year ago

Flutter 3.13.2 environment: sdk: '>=3.1.0 <4.0.0'


After a specific dio 'post' call I'm getting this error:

Unhandled exception:
Invalid argument(s): Iterables do not have same length.
#0      MapBase._fillMapWithIterables (dart:collection/maps.dart:178:7)
#1      new LinkedHashMap.fromIterables (dart:collection/linked_hash_map.dart:246:13)
#2      Substitution.fromPairs (package:kernel/type_algebra.dart:263:13)
#3      InferenceVisitorBase.getGetterTypeForMemberTarget (package:front_end/src/fasta/type_inference/inference_visitor_base.dart:1465:35)
#4      InstanceAccessTarget.getGetterType (package:front_end/src/fasta/type_inference/object_access_target.dart:489:30)
#5      InferenceVisitorImpl._computePropertyGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:6663:36)
#6      InferenceVisitorImpl.visitPropertyGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:7672:61)
#7      PropertyGet.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:2984:20)

#8      InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:257:27)
#9      InferenceVisitorImpl.inferNullAwareExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:310:40)
#10     InferenceVisitorImpl.visitIndexGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:5227:48)
#11     IndexGet.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:1824:20)
#12     InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:257:27)
#13     InferenceVisitorImpl.inferNullAwareExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:310:40)
#14     InferenceVisitorImpl.visitIndexGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:5227:48)
#15     IndexGet.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:1824:20)
#16     InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:257:27)
#17     InferenceVisitorImpl.inferNullAwareExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:310:40)
#18     InferenceVisitorImpl.visitIndexGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:5227:48)
#19     IndexGet.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:1824:20)
#20     InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:257:27)
#21     InferenceVisitorImpl.inferNullAwareExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:310:40)
#22     InferenceVisitorImpl.visitIndexGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:5227:48)
#23     IndexGet.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:1824:20)
#24     InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:257:27)
#25     InferenceVisitorImpl.inferNullAwareExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:310:40)
#26     InferenceVisitorImpl.visitIndexGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:5227:48)
#27     IndexGet.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:1824:20)
#28     InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:257:27)
#29     InferenceVisitorImpl.inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:291:40)
#30     InferenceVisitorImpl.visitReturnStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:7894:11)
#31     ReturnStatement.accept (package:kernel/ast.dart:10127:43)
#32     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:242:26)
#33     TypeInferrerImpl.inferFunctionBody (package:front_end/src/fasta/type_inference/type_inferrer.dart:198:17)
#34     BodyBuilder.parseSingleExpression (package:front_end/src/fasta/kernel/body_builder.dart:1780:62)
#35     SourceLoader.buildExpression (package:front_end/src/fasta/source/source_loader.dart:1320:21)
<asynchronous suspension>
#36     IncrementalCompiler.compileExpression.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:2033:39)
<asynchronous suspension>
#37     IncrementalCompiler.compileExpression (package:front_end/src/fasta/incremental_compiler.dart:1853:12)
<asynchronous suspension>
#38     FrontendCompiler.compileExpression (package:frontend_server/frontend_server.dart:981:28)

<asynchronous suspension>
#39     listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1452:11)
<asynchronous suspension>

3
the Dart compiler exited unexpectedly.
Exited (1)
johnniwinther commented 1 year ago

@burekas7 Did this happen when evaluation an explicit expression during debugging or when hovering expressions in the editor? Also was this part of a hot-reload cycle (i.e. was the code "recently" modified) ?

heshesh2010 commented 1 year ago

+1 , got same error when hovering on the expressions in VS CODE editor , using Dio package to debug the responses .

sdk: ">=2.19.2 <4.0.0"

flutter doctor `Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.13.2, on macOS 13.5 22G74 darwin-x64, locale en-EG) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.2) [✓] VS Code (version 1.81.1) [✓] Connected device (3 available) [✓] Network resources

• No issues found!`

johnniwinther commented 1 year ago

@heshesh2010 Do you have any idea what expression was?

ChaserVasya commented 1 year ago

same

cmdrKhonan commented 1 year ago

+1 here having a similar issue :

     List<List<int>> l = List.generate(list.length, (index) => []);
     List<dynamic> guide = [
       {
         "field": null,
         "nextList": null,
         "selection": l,
         "max_selected": 1000,
       }
     ];

this generate a debugger crash :

Unhandled exception:
Invalid argument(s): Iterables do not have same length.
#0      MapBase._fillMapWithIterables (dart:collection/maps.dart:178:7)
#1      new LinkedHashMap.fromIterables (dart:collection/linked_hash_map.dart:246:13)
#2      Substitution.fromPairs (package:kernel/type_algebra.dart:263:13)
#3      InferenceVisitorBase.getGetterTypeForMemberTarget (package:front_end/src/fasta/type_inference/inference_visitor_base.dart:1465:35)
johnniwinther commented 1 year ago

This seems to originate from a bad encoding of the arguments passed to the expression compiler - at least I can recreate the crash by creating such a bad message. I'm still not still sure the where in the tool chain this encoding is created, though.

Likely related to https://github.com/dart-lang/sdk/issues/53382

johnniwinther commented 1 year ago

cc @jensjoha

johnniwinther commented 1 year ago

@jensjoha @mraleph Can we be sure that a raw type of a generic class in the VM has the right number of types arguments? I.e. could the VM be creating the encoding ["dart:core", "List", "1", "0"] for List in CollectStringifiedType ?

mraleph commented 1 year ago

@johnniwinther I think they should have correct length. Type object in the VM should carry TAV which matches the number of type parameters the class has (cc @alexmarkov)

However the code in CollectStringifiedType is a bit suspicious - it does not seem to handle raw types (e.g. List<dynamic>) correctly. VM used to denote those using null TAV and CollectStringifiedType does not seem to handle that at all. Maybe we can try to reproduce by trying expression compilation in a context with a variable which has a raw type, e.g. final v = <dynamic>[] and see if it blows up?

mraleph commented 1 year ago

Yeah it reproduces quite trivially with the following test:

Regression test ```dart import 'dart:developer'; import 'package:observatory/models.dart' show InstanceKind; import 'package:observatory/service_io.dart'; import 'package:test/test.dart'; import 'service_test_common.dart'; import 'test_helper.dart'; void testFunction() { List v = [1, 2, '3']; debugger(); print("v = $v"); } var tests = [ hasStoppedAtBreakpoint, (Isolate isolate) async { final result = await isolate.evalFrame(0, '''v.length'''); print(result); final instance = result as Instance; expect(instance.valueAsString, equals('3')); expect(instance.kind, equals(InstanceKind.int)); }, ]; main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); ```

And if I put RELEASE_ASSERT(!srcArguments.IsNull()); it triggers. The fix should be fairly trivial - just handle this case. I can patch it up.

RickZzDev commented 1 year ago

In my case i was having this problem using for each to desserialize a json response that was inside a list, when a change it to a "for in" it stopped to crash

burekas7 commented 1 year ago

Does anyone know if this bug was fixed? Because I see this issue is closed.

Should I need to update the dart sdk version?

@mraleph @johnniwinther

johnniwinther commented 1 year ago

The issue has been fixed in the Dart repository and is available in the lastest dev release. It will be in the the next beta and stable releases.

shawnAshton commented 1 year ago

@johnniwinther I see you said this 3 weeks ago, so I made sure to update to new flutter & dart versions released after your comment.

(@mraleph tagging you as you authored the fix 3 weeks ago)

I still experience this issue with these updates that were released sept 27th (about 2 weeks after your comment). flutter: 3.13.6 dart: 3.1.3 environment: sdk: '>=3.1.3 <4.0.0'

Unhandled exception:
Invalid argument(s): Iterables do not have same length.
#0      MapBase._fillMapWithIterables (dart:collection/maps.dart:178:7)
#1      new LinkedHashMap.fromIterables (dart:collection/linked_hash_map.dart:246:13)
#2      Substitution.fromPairs (package:kernel/type_algebra.dart:263:13)
#3      InferenceVisitorBase.getGetterTypeForMemberTarget (package:front_end/src/fasta/type_inference/inference_visitor_base.dart:1465:35)
#5      InferenceVisitorImpl._computePropertyGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:6663:36)
#4      InstanceAccessTarget.getGetterType (package:front_end/src/fasta/type_inference/object_access_target.dart:489:30)
#6      InferenceVisitorImpl.visitPropertyGet (package:front_end/src/fasta/type_inference/inference_visitor.dart:7672:61)
#7      PropertyGet.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:2984:20)
#8      InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:257:27)
#9      InferenceVisitorImpl.inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:291:40)
#10     InferenceVisitorImpl.visitReturnStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:7894:11)
#11     ReturnStatement.accept (package:kernel/ast.dart:10127:43)

#12     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:242:26)
#13     TypeInferrerImpl.inferFunctionBody (package:front_end/src/fasta/type_inference/type_inferrer.dart:198:17)
#14     BodyBuilder.parseSingleExpression (package:front_end/src/fasta/kernel/body_builder.dart:1780:62)
#15     SourceLoader.buildExpression (package:front_end/src/fasta/source/source_loader.dart:1320:21)
<asynchronous suspension>
#16     IncrementalCompiler.compileExpression.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:2033:39)
<asynchronous suspension>
#17     IncrementalCompiler.compileExpression (package:front_end/src/fasta/incremental_compiler.dart:1853:12)
<asynchronous suspension>
#18     FrontendCompiler.compileExpression (package:frontend_server/frontend_server.dart:981:28)
<asynchronous suspension>
#19     listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1452:11)
<asynchronous suspension>
jensjoha commented 1 year ago

It seems you're on flutter stable meaning you don't get the dev releases of dart.

shawnAshton commented 1 year ago

It seems you're on flutter stable meaning you don't get the dev releases of dart.

As was mentioned above, It will be in the the next beta and stable releases.. I do see that that doesn't specify which next stable release though...

mraleph commented 1 year ago

@shawnAshton next stable release means Dart 3.2.

kashiflab commented 11 months ago

It seems you're on flutter stable meaning you don't get the dev releases of dart.

As was mentioned above, It will be in the next beta and stable releases.. I do see that that doesn't specify which next stable release though...

@shawnAshton @mraleph Please push the latest release on the stable branch. I am stuck nothing is working, my timelines are disturbed because of this error.

burekas7 commented 11 months ago

@kashiflab Agree. It is completely difficult to debug api calls like this, I put a breakpoint and a few seconds later it crashes the application and debug.

When the stable release with the fix will be ready for use? @mraleph @johnniwinther

mraleph commented 11 months ago

Stable release is in the final rounds of testing and preparations for release. You could switch to Flutter beta channel if you want the fix already today.

gabrielgiovans commented 11 months ago

I bring good news guys, today I was looking for the problem and came across this topic. The new version of flutter (3.16.0) released yesterday has fixed the problem.