File tree 4 files changed +66
-1
lines changed
4 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -10091,7 +10091,7 @@ abstract final class IndexExpression
10091
10091
}
10092
10092
10093
10093
final class IndexExpressionImpl extends ExpressionImpl
10094
- with NullShortableExpressionImpl
10094
+ with NullShortableExpressionImpl, DotShorthandMixin
10095
10095
implements IndexExpression {
10096
10096
@override
10097
10097
Token? period;
Original file line number Diff line number Diff line change @@ -3074,6 +3074,12 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
3074
3074
TypeImpl contextType = UnknownInferredType .instance,
3075
3075
}) {
3076
3076
inferenceLogWriter? .enterExpression (node, contextType);
3077
+
3078
+ // If [isDotShorthand] is set, cache the context type for resolution.
3079
+ if (isDotShorthand (node)) {
3080
+ pushDotShorthandContext (node, SharedTypeSchemaView (contextType));
3081
+ }
3082
+
3077
3083
checkUnreachableNode (node);
3078
3084
3079
3085
var target = node.target;
@@ -3132,6 +3138,11 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
3132
3138
nullShortingTermination (node, rewrittenExpression: replacement);
3133
3139
_insertImplicitCallReference (replacement, contextType: contextType);
3134
3140
nullSafetyDeadCodeVerifier.verifyIndexExpression (node);
3141
+
3142
+ if (isDotShorthand (node)) {
3143
+ popDotShorthandContext ();
3144
+ }
3145
+
3135
3146
inferenceLogWriter? .exitExpression (node);
3136
3147
}
3137
3148
Original file line number Diff line number Diff line change @@ -321,6 +321,35 @@ DotShorthandInvocation
321
321
''' );
322
322
}
323
323
324
+ test_equality_indexExpression () async {
325
+ await assertNoErrorsInCode (r'''
326
+ class C {
327
+ int x;
328
+ C(this.x);
329
+ static List<C> instances() => [C(1)];
330
+ }
331
+
332
+ void main() {
333
+ print(C(1) == .instances()[0]);
334
+ }
335
+ ''' );
336
+
337
+ var identifier = findNode.singleDotShorthandInvocation;
338
+ assertResolvedNodeText (identifier, r'''
339
+ DotShorthandInvocation
340
+ period: .
341
+ memberName: SimpleIdentifier
342
+ token: instances
343
+ element: <testLibraryFragment>::@class::C::@method::instances#element
344
+ staticType: List<C> Function()
345
+ argumentList: ArgumentList
346
+ leftParenthesis: (
347
+ rightParenthesis: )
348
+ staticInvokeType: List<C> Function()
349
+ staticType: List<C>
350
+ ''' );
351
+ }
352
+
324
353
test_extensionType () async {
325
354
await assertNoErrorsInCode (r'''
326
355
extension type C(int integer) {
Original file line number Diff line number Diff line change @@ -270,6 +270,31 @@ DotShorthandPropertyAccess
270
270
''' );
271
271
}
272
272
273
+ test_equality_indexExpression () async {
274
+ await assertNoErrorsInCode (r'''
275
+ class C {
276
+ int x;
277
+ C(this.x);
278
+ static List<C> instances = [C(1)];
279
+ }
280
+
281
+ void main() {
282
+ print(C(1) == .instances[0]);
283
+ }
284
+ ''' );
285
+
286
+ var identifier = findNode.singleDotShorthandPropertyAccess;
287
+ assertResolvedNodeText (identifier, r'''
288
+ DotShorthandPropertyAccess
289
+ period: .
290
+ propertyName: SimpleIdentifier
291
+ token: instances
292
+ element: <testLibraryFragment>::@class::C::@getter::instances#element
293
+ staticType: List<C>
294
+ staticType: List<C>
295
+ ''' );
296
+ }
297
+
273
298
test_equality_pattern () async {
274
299
await assertNoErrorsInCode ('''
275
300
enum Color { red, blue }
You can’t perform that action at this time.
0 commit comments