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 <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov
2020-10-22 19:27:10 +00:00
committed by commit-bot@chromium.org
parent feeb7ad461
commit 088524efa6
3 changed files with 86 additions and 2 deletions
@@ -396,6 +396,14 @@ class ApplyResolutionVisitor extends ThrowingAstVisitor<void> {
_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);
@@ -915,11 +915,11 @@ class AstBinaryWriter extends ThrowingAstVisitor<LinkedNodeBuilder> {
@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,
@@ -2830,6 +2830,47 @@ const List<P<dynamic>> values = /*typeArgs=P<dynamic>*/[/*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<int> a;
constantInitializer
ListLiteral
elements
IntegerLiteral
literal: 0
staticType: int
staticType: List<int>
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<int>
token: a
''',
withFullyResolvedAst: true);
}
test_const_invalid_intLiteral() async {
var library = await checkLibrary(r'''
const int x = 0x;