This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +86
-2
lines changed Expand file tree Collapse file tree 3 files changed +86
-2
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,14 @@ class ApplyResolutionVisitor extends ThrowingAstVisitor<void> {
396396 _namespaceDirective (node);
397397 }
398398
399+ @override
400+ void visitIndexExpression (IndexExpression node) {
401+ node.target? .accept (this );
402+ node.index.accept (this );
403+ node.staticElement = _nextElement ();
404+ _expression (node);
405+ }
406+
399407 @override
400408 void visitInstanceCreationExpression (InstanceCreationExpression node) {
401409 node.constructorName.accept (this );
Original file line number Diff line number Diff line change @@ -915,11 +915,11 @@ class AstBinaryWriter extends ThrowingAstVisitor<LinkedNodeBuilder> {
915915 @override
916916 LinkedNodeBuilder visitIndexExpression (IndexExpression node) {
917917 var builder = LinkedNodeBuilder .indexExpression (
918- indexExpression_index: node.index.accept (this ),
919918 indexExpression_target: node.target? .accept (this ),
920- expression_type : _writeType ( 'staticType' , node.staticType ),
919+ indexExpression_index : node.index. accept ( this ),
921920 );
922921 _componentsOfElement (node.staticElement);
922+ _storeExpression (builder, node);
923923 builder.flags = AstBinaryFlags .encode (
924924 hasPeriod: node.period != null ,
925925 hasQuestion: node.question != null ,
Original file line number Diff line number Diff line change @@ -2830,6 +2830,47 @@ const List<P<dynamic>> values = /*typeArgs=P<dynamic>*/[/*typeArgs=dynamic*/
28302830 withTypes: true );
28312831 }
28322832
2833+ test_const_invalid_cascade_indexExpression () async {
2834+ var library = await checkLibrary (r'''
2835+ class A {
2836+ int operator[](int _) => 0;
2837+ }
2838+ const b = A()..[0];
2839+ ''' );
2840+
2841+ checkElementText (
2842+ library,
2843+ r'''
2844+ class A {
2845+ int [](int _) {}
2846+ }
2847+ const A b;
2848+ constantInitializer
2849+ CascadeExpression
2850+ cascadeSections
2851+ IndexExpression
2852+ index: IntegerLiteral
2853+ literal: 0
2854+ staticType: int
2855+ period: ..
2856+ staticElement: self::@class::A::@method::[]
2857+ staticType: int
2858+ staticType: A
2859+ target: InstanceCreationExpression
2860+ argumentList: ArgumentList
2861+ constructorName: ConstructorName
2862+ staticElement: self::@class::A::@constructor::•
2863+ type: TypeName
2864+ name: SimpleIdentifier
2865+ staticElement: self::@class::A
2866+ staticType: null
2867+ token: A
2868+ type: A
2869+ staticType: A
2870+ ''' ,
2871+ withFullyResolvedAst: true );
2872+ }
2873+
28332874 test_const_invalid_field_const () async {
28342875 var library = await checkLibrary (r'''
28352876class C {
@@ -2861,6 +2902,41 @@ int foo() {}
28612902''' );
28622903 }
28632904
2905+ test_const_invalid_indexExpression () async {
2906+ var library = await checkLibrary (r'''
2907+ const a = [0];
2908+ const b = a[0];
2909+ ''' );
2910+
2911+ checkElementText (
2912+ library,
2913+ r'''
2914+ const List<int> a;
2915+ constantInitializer
2916+ ListLiteral
2917+ elements
2918+ IntegerLiteral
2919+ literal: 0
2920+ staticType: int
2921+ staticType: List<int>
2922+ const int b;
2923+ constantInitializer
2924+ IndexExpression
2925+ index: IntegerLiteral
2926+ literal: 0
2927+ staticType: int
2928+ staticElement: MethodMember
2929+ base: dart:core::@class::List::@method::[]
2930+ substitution: {E: int}
2931+ staticType: int
2932+ target: SimpleIdentifier
2933+ staticElement: self::@getter::a
2934+ staticType: List<int>
2935+ token: a
2936+ ''' ,
2937+ withFullyResolvedAst: true );
2938+ }
2939+
28642940 test_const_invalid_intLiteral () async {
28652941 var library = await checkLibrary (r'''
28662942const int x = 0x;
You can’t perform that action at this time.
0 commit comments