Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1673373002: Test some corner cases of shadowing between scopes when summarizing constants. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 1522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 _assertUnlinkedConst(variable.constExpr, operators: [ 1533 _assertUnlinkedConst(variable.constExpr, operators: [
1534 UnlinkedConstOperation.pushInt, 1534 UnlinkedConstOperation.pushInt,
1535 UnlinkedConstOperation.pushInt, 1535 UnlinkedConstOperation.pushInt,
1536 UnlinkedConstOperation.subtract 1536 UnlinkedConstOperation.subtract
1537 ], ints: [ 1537 ], ints: [
1538 1, 1538 1,
1539 2 1539 2
1540 ]); 1540 ]);
1541 } 1541 }
1542 1542
1543 test_constExpr_classMember_shadows_typeParam() {
1544 // Although it is an error for a class member to have the same name as a
1545 // type parameter, the spec makes it clear that the class member scope is
1546 // nested inside the type parameter scope. So go ahead and verify that
1547 // the class member shadows the type parameter.
1548 String text = '''
1549 class C<T> {
1550 static const T = null;
1551 final x;
1552 const C() : x = T;
1553 }
1554 ''';
1555 UnlinkedClass cls = serializeClassText(text, allowErrors: true);
1556 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression,
1557 operators: [
1558 UnlinkedConstOperation.pushReference
1559 ],
1560 referenceValidators: [
1561 (EntityRef r) => checkTypeRef(r, null, null, 'T',
1562 expectedKind: ReferenceKind.propertyAccessor,
1563 prefixExpectations: [
1564 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C',
1565 numTypeParameters: 1)
1566 ])
1567 ]);
1568 }
1569
1543 test_constExpr_conditional() { 1570 test_constExpr_conditional() {
1544 UnlinkedVariable variable = 1571 UnlinkedVariable variable =
1545 serializeVariableText('const v = true ? 1 : 2;', allowErrors: true); 1572 serializeVariableText('const v = true ? 1 : 2;', allowErrors: true);
1546 _assertUnlinkedConst(variable.constExpr, operators: [ 1573 _assertUnlinkedConst(variable.constExpr, operators: [
1547 UnlinkedConstOperation.pushTrue, 1574 UnlinkedConstOperation.pushTrue,
1548 UnlinkedConstOperation.pushInt, 1575 UnlinkedConstOperation.pushInt,
1549 UnlinkedConstOperation.pushInt, 1576 UnlinkedConstOperation.pushInt,
1550 UnlinkedConstOperation.conditional 1577 UnlinkedConstOperation.conditional
1551 ], ints: [ 1578 ], ints: [
1552 1, 1579 1,
1553 2 1580 2
1554 ]); 1581 ]);
1555 } 1582 }
1556 1583
1584 test_constExpr_constructorParam_shadows_classMember() {
1585 UnlinkedClass cls = serializeClassText('''
1586 class C {
1587 static const a = null;
1588 final b;
1589 const C(a) : b = a;
1590 }
1591 ''');
1592 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression,
1593 operators: [UnlinkedConstOperation.pushConstructorParameter],
1594 strings: ['a']);
1595 }
1596
1597 test_constExpr_constructorParam_shadows_typeParam() {
1598 UnlinkedClass cls = serializeClassText('''
1599 class C<T> {
1600 final x;
1601 const C(T) : x = T;
1602 }
1603 ''');
1604 _assertUnlinkedConst(cls.executables[0].constantInitializers[0].expression,
1605 operators: [UnlinkedConstOperation.pushConstructorParameter],
1606 strings: ['T']);
1607 }
1608
1557 test_constExpr_identical() { 1609 test_constExpr_identical() {
1558 UnlinkedVariable variable = 1610 UnlinkedVariable variable =
1559 serializeVariableText('const v = identical(42, null);'); 1611 serializeVariableText('const v = identical(42, null);');
1560 _assertUnlinkedConst(variable.constExpr, operators: [ 1612 _assertUnlinkedConst(variable.constExpr, operators: [
1561 UnlinkedConstOperation.pushInt, 1613 UnlinkedConstOperation.pushInt,
1562 UnlinkedConstOperation.pushNull, 1614 UnlinkedConstOperation.pushNull,
1563 UnlinkedConstOperation.identical 1615 UnlinkedConstOperation.identical
1564 ], ints: [ 1616 ], ints: [
1565 42 1617 42
1566 ]); 1618 ]);
(...skipping 4386 matching lines...) Expand 10 before | Expand all | Expand 10 after
5953 final String absoluteUri; 6005 final String absoluteUri;
5954 final String relativeUri; 6006 final String relativeUri;
5955 final int numTypeParameters; 6007 final int numTypeParameters;
5956 6008
5957 _PrefixExpectation(this.kind, this.name, 6009 _PrefixExpectation(this.kind, this.name,
5958 {this.inLibraryDefiningUnit: false, 6010 {this.inLibraryDefiningUnit: false,
5959 this.absoluteUri, 6011 this.absoluteUri,
5960 this.relativeUri, 6012 this.relativeUri,
5961 this.numTypeParameters: 0}); 6013 this.numTypeParameters: 0});
5962 } 6014 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698