diff --git a/pkg/analyzer/lib/src/summary2/apply_resolution.dart b/pkg/analyzer/lib/src/summary2/apply_resolution.dart index e24a6429cef..f3f4e132cd4 100644 --- a/pkg/analyzer/lib/src/summary2/apply_resolution.dart +++ b/pkg/analyzer/lib/src/summary2/apply_resolution.dart @@ -396,6 +396,14 @@ class ApplyResolutionVisitor extends ThrowingAstVisitor { _namespaceDirective(node); } + @override + void visitIndexExpression(IndexExpression node) { + node.target?.accept(this); + node.index.accept(this); + node.staticElement = _nextElement(); + _expression(node); + } + @override void visitInstanceCreationExpression(InstanceCreationExpression node) { node.constructorName.accept(this); diff --git a/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart b/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart index 175ffc96d66..f9542a250ff 100644 --- a/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart +++ b/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart @@ -915,11 +915,11 @@ class AstBinaryWriter extends ThrowingAstVisitor { @override LinkedNodeBuilder visitIndexExpression(IndexExpression node) { var builder = LinkedNodeBuilder.indexExpression( - indexExpression_index: node.index.accept(this), indexExpression_target: node.target?.accept(this), - expression_type: _writeType('staticType', node.staticType), + indexExpression_index: node.index.accept(this), ); _componentsOfElement(node.staticElement); + _storeExpression(builder, node); builder.flags = AstBinaryFlags.encode( hasPeriod: node.period != null, hasQuestion: node.question != null, diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart index a3cfc3cc645..a06e28fd37a 100644 --- a/pkg/analyzer/test/src/summary/resynthesize_common.dart +++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart @@ -2830,6 +2830,47 @@ const List> values = /*typeArgs=P*/[/*typeArgs=dynamic*/ withTypes: true); } + test_const_invalid_cascade_indexExpression() async { + var library = await checkLibrary(r''' +class A { + int operator[](int _) => 0; +} +const b = A()..[0]; +'''); + + checkElementText( + library, + r''' +class A { + int [](int _) {} +} +const A b; + constantInitializer + CascadeExpression + cascadeSections + IndexExpression + index: IntegerLiteral + literal: 0 + staticType: int + period: .. + staticElement: self::@class::A::@method::[] + staticType: int + staticType: A + target: InstanceCreationExpression + argumentList: ArgumentList + constructorName: ConstructorName + staticElement: self::@class::A::@constructor::• + type: TypeName + name: SimpleIdentifier + staticElement: self::@class::A + staticType: null + token: A + type: A + staticType: A +''', + withFullyResolvedAst: true); + } + test_const_invalid_field_const() async { var library = await checkLibrary(r''' class C { @@ -2861,6 +2902,41 @@ int foo() {} '''); } + test_const_invalid_indexExpression() async { + var library = await checkLibrary(r''' +const a = [0]; +const b = a[0]; +'''); + + checkElementText( + library, + r''' +const List a; + constantInitializer + ListLiteral + elements + IntegerLiteral + literal: 0 + staticType: int + staticType: List +const int b; + constantInitializer + IndexExpression + index: IntegerLiteral + literal: 0 + staticType: int + staticElement: MethodMember + base: dart:core::@class::List::@method::[] + substitution: {E: int} + staticType: int + target: SimpleIdentifier + staticElement: self::@getter::a + staticType: List + token: a +''', + withFullyResolvedAst: true); + } + test_const_invalid_intLiteral() async { var library = await checkLibrary(r''' const int x = 0x;