Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 088524e

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Issue 43890. Implement applying resolution to IndexExpression.
Bug: dart-lang/sdk#43890 Change-Id: I537d157ca9ff583b09e7c09ff580202b9dc4ced3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168778 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent feeb7ad commit 088524e

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

pkg/analyzer/lib/src/summary2/apply_resolution.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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,

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff 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'''
28352876
class 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'''
28662942
const int x = 0x;

0 commit comments

Comments
 (0)