From 088524efa6a35bd64ea2ec00c60dae3111298334 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 22 Oct 2020 19:27:10 +0000 Subject: [PATCH] Issue 43890. Implement applying resolution to IndexExpression. Bug: https://github.com/dart-lang/sdk/issues/43890 Change-Id: I537d157ca9ff583b09e7c09ff580202b9dc4ced3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168778 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- .../lib/src/summary2/apply_resolution.dart | 8 ++ .../lib/src/summary2/ast_binary_writer.dart | 4 +- .../test/src/summary/resynthesize_common.dart | 76 +++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) 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;