| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 class A { | 690 class A { |
| 691 final int x; | 691 final int x; |
| 692 const A(this.x); | 692 const A(this.x); |
| 693 } | 693 } |
| 694 var v = const A(null);'''); | 694 var v = const A(null);'''); |
| 695 resolve(source); | 695 resolve(source); |
| 696 assertNoErrors(source); | 696 assertNoErrors(source); |
| 697 verify([source]); | 697 verify([source]); |
| 698 } | 698 } |
| 699 | 699 |
| 700 void test_fieldFormalParameterAssignableToField_typeSubstitution() { | |
| 701 // foo has the runtime type dynamic -> dynamic, so it should be assignable | |
| 702 // to A.f. | |
| 703 Source source = addSource(r''' | |
| 704 class A<T> { | |
| 705 final T x; | |
| 706 const A(this.x); | |
| 707 } | |
| 708 var v = const A<int>(3);'''); | |
| 709 resolve(source); | |
| 710 assertNoErrors(source); | |
| 711 verify([source]); | |
| 712 } | |
| 713 | |
| 714 void test_fieldFormalParameterAssignableToField_typedef() { | 700 void test_fieldFormalParameterAssignableToField_typedef() { |
| 715 // foo has the runtime type dynamic -> dynamic, so it should be assignable | 701 // foo has the runtime type dynamic -> dynamic, so it should be assignable |
| 716 // to A.f. | 702 // to A.f. |
| 717 Source source = addSource(r''' | 703 Source source = addSource(r''' |
| 718 typedef String Int2String(int x); | 704 typedef String Int2String(int x); |
| 719 class A { | 705 class A { |
| 720 final Int2String f; | 706 final Int2String f; |
| 721 const A(this.f); | 707 const A(this.f); |
| 722 } | 708 } |
| 723 foo(x) => 1; | 709 foo(x) => 1; |
| 724 var v = const A(foo);'''); | 710 var v = const A(foo);'''); |
| 725 resolve(source); | 711 resolve(source); |
| 726 assertNoErrors(source); | 712 assertNoErrors(source); |
| 727 verify([source]); | 713 verify([source]); |
| 714 } |
| 715 |
| 716 void test_fieldFormalParameterAssignableToField_typeSubstitution() { |
| 717 // foo has the runtime type dynamic -> dynamic, so it should be assignable |
| 718 // to A.f. |
| 719 Source source = addSource(r''' |
| 720 class A<T> { |
| 721 final T x; |
| 722 const A(this.x); |
| 723 } |
| 724 var v = const A<int>(3);'''); |
| 725 resolve(source); |
| 726 assertNoErrors(source); |
| 727 verify([source]); |
| 728 } | 728 } |
| 729 | 729 |
| 730 void test_fieldFormalParameterNotAssignableToField() { | 730 void test_fieldFormalParameterNotAssignableToField() { |
| 731 Source source = addSource(r''' | 731 Source source = addSource(r''' |
| 732 class A { | 732 class A { |
| 733 final int x; | 733 final int x; |
| 734 const A(this.x); | 734 const A(this.x); |
| 735 } | 735 } |
| 736 var v = const A('foo');'''); | 736 var v = const A('foo');'''); |
| 737 resolve(source); | 737 resolve(source); |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 left.propagatedType = numType; | 1340 left.propagatedType = numType; |
| 1341 BinaryExpression expression = | 1341 BinaryExpression expression = |
| 1342 AstFactory.binaryExpression(left, TokenType.PLUS, AstFactory.identifier3
("j")); | 1342 AstFactory.binaryExpression(left, TokenType.PLUS, AstFactory.identifier3
("j")); |
| 1343 _resolveNode(expression); | 1343 _resolveNode(expression); |
| 1344 expect(expression.staticElement, isNull); | 1344 expect(expression.staticElement, isNull); |
| 1345 expect(expression.propagatedElement, getMethod(numType, "+")); | 1345 expect(expression.propagatedElement, getMethod(numType, "+")); |
| 1346 _listener.assertNoErrors(); | 1346 _listener.assertNoErrors(); |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 void test_visitBreakStatement_withLabel() { | 1349 void test_visitBreakStatement_withLabel() { |
| 1350 // loop: while (true) { |
| 1351 // break loop; |
| 1352 // } |
| 1350 String label = "loop"; | 1353 String label = "loop"; |
| 1351 LabelElementImpl labelElement = | 1354 LabelElementImpl labelElement = |
| 1352 new LabelElementImpl(AstFactory.identifier3(label), false, false); | 1355 new LabelElementImpl(AstFactory.identifier3(label), false, false); |
| 1353 BreakStatement statement = AstFactory.breakStatement2(label); | 1356 BreakStatement breakStatement = AstFactory.breakStatement2(label); |
| 1354 expect(_resolveBreak(statement, labelElement), same(labelElement)); | 1357 Expression condition = AstFactory.booleanLiteral(true); |
| 1358 WhileStatement whileStatement = |
| 1359 AstFactory.whileStatement(condition, breakStatement); |
| 1360 expect( |
| 1361 _resolveBreak(breakStatement, labelElement, whileStatement), |
| 1362 same(labelElement)); |
| 1363 expect(breakStatement.target, same(whileStatement)); |
| 1355 _listener.assertNoErrors(); | 1364 _listener.assertNoErrors(); |
| 1356 } | 1365 } |
| 1357 | 1366 |
| 1358 void test_visitBreakStatement_withoutLabel() { | 1367 void test_visitBreakStatement_withoutLabel() { |
| 1359 BreakStatement statement = AstFactory.breakStatement(); | 1368 BreakStatement statement = AstFactory.breakStatement(); |
| 1360 _resolveStatement(statement, null); | 1369 _resolveStatement(statement, null, null); |
| 1361 _listener.assertNoErrors(); | 1370 _listener.assertNoErrors(); |
| 1362 } | 1371 } |
| 1363 | 1372 |
| 1364 void test_visitConstructorName_named() { | 1373 void test_visitConstructorName_named() { |
| 1365 ClassElementImpl classA = ElementFactory.classElement2("A"); | 1374 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1366 String constructorName = "a"; | 1375 String constructorName = "a"; |
| 1367 ConstructorElement constructor = | 1376 ConstructorElement constructor = |
| 1368 ElementFactory.constructorElement2(classA, constructorName); | 1377 ElementFactory.constructorElement2(classA, constructorName); |
| 1369 classA.constructors = <ConstructorElement>[constructor]; | 1378 classA.constructors = <ConstructorElement>[constructor]; |
| 1370 ConstructorName name = | 1379 ConstructorName name = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1381 ElementFactory.constructorElement2(classA, constructorName); | 1390 ElementFactory.constructorElement2(classA, constructorName); |
| 1382 classA.constructors = <ConstructorElement>[constructor]; | 1391 classA.constructors = <ConstructorElement>[constructor]; |
| 1383 ConstructorName name = | 1392 ConstructorName name = |
| 1384 AstFactory.constructorName(AstFactory.typeName(classA), constructorName)
; | 1393 AstFactory.constructorName(AstFactory.typeName(classA), constructorName)
; |
| 1385 _resolveNode(name); | 1394 _resolveNode(name); |
| 1386 expect(name.staticElement, same(constructor)); | 1395 expect(name.staticElement, same(constructor)); |
| 1387 _listener.assertNoErrors(); | 1396 _listener.assertNoErrors(); |
| 1388 } | 1397 } |
| 1389 | 1398 |
| 1390 void test_visitContinueStatement_withLabel() { | 1399 void test_visitContinueStatement_withLabel() { |
| 1400 // loop: while (true) { |
| 1401 // continue loop; |
| 1402 // } |
| 1391 String label = "loop"; | 1403 String label = "loop"; |
| 1392 LabelElementImpl labelElement = | 1404 LabelElementImpl labelElement = |
| 1393 new LabelElementImpl(AstFactory.identifier3(label), false, false); | 1405 new LabelElementImpl(AstFactory.identifier3(label), false, false); |
| 1394 ContinueStatement statement = AstFactory.continueStatement(label); | 1406 ContinueStatement continueStatement = AstFactory.continueStatement(label); |
| 1395 expect(_resolveContinue(statement, labelElement), same(labelElement)); | 1407 Expression condition = AstFactory.booleanLiteral(true); |
| 1408 WhileStatement whileStatement = |
| 1409 AstFactory.whileStatement(condition, continueStatement); |
| 1410 expect( |
| 1411 _resolveContinue(continueStatement, labelElement, whileStatement), |
| 1412 same(labelElement)); |
| 1413 expect(continueStatement.target, same(whileStatement)); |
| 1396 _listener.assertNoErrors(); | 1414 _listener.assertNoErrors(); |
| 1397 } | 1415 } |
| 1398 | 1416 |
| 1399 void test_visitContinueStatement_withoutLabel() { | 1417 void test_visitContinueStatement_withoutLabel() { |
| 1400 ContinueStatement statement = AstFactory.continueStatement(); | 1418 ContinueStatement statement = AstFactory.continueStatement(); |
| 1401 _resolveStatement(statement, null); | 1419 _resolveStatement(statement, null, null); |
| 1402 _listener.assertNoErrors(); | 1420 _listener.assertNoErrors(); |
| 1403 } | 1421 } |
| 1404 | 1422 |
| 1405 void test_visitExportDirective_noCombinators() { | 1423 void test_visitExportDirective_noCombinators() { |
| 1406 ExportDirective directive = AstFactory.exportDirective2(null); | 1424 ExportDirective directive = AstFactory.exportDirective2(null); |
| 1407 directive.element = ElementFactory.exportFor( | 1425 directive.element = ElementFactory.exportFor( |
| 1408 ElementFactory.library(_definingLibrary.context, "lib")); | 1426 ElementFactory.library(_definingLibrary.context, "lib")); |
| 1409 _resolveNode(directive); | 1427 _resolveNode(directive); |
| 1410 _listener.assertNoErrors(); | 1428 _listener.assertNoErrors(); |
| 1411 } | 1429 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 InterfaceType numType = _typeProvider.numType; | 1621 InterfaceType numType = _typeProvider.numType; |
| 1604 SimpleIdentifier operand = AstFactory.identifier3("i"); | 1622 SimpleIdentifier operand = AstFactory.identifier3("i"); |
| 1605 operand.staticType = numType; | 1623 operand.staticType = numType; |
| 1606 PostfixExpression expression = | 1624 PostfixExpression expression = |
| 1607 AstFactory.postfixExpression(operand, TokenType.PLUS_PLUS); | 1625 AstFactory.postfixExpression(operand, TokenType.PLUS_PLUS); |
| 1608 _resolveNode(expression); | 1626 _resolveNode(expression); |
| 1609 expect(expression.staticElement, getMethod(numType, "+")); | 1627 expect(expression.staticElement, getMethod(numType, "+")); |
| 1610 _listener.assertNoErrors(); | 1628 _listener.assertNoErrors(); |
| 1611 } | 1629 } |
| 1612 | 1630 |
| 1613 void test_visitPrefixExpression() { | |
| 1614 InterfaceType numType = _typeProvider.numType; | |
| 1615 SimpleIdentifier operand = AstFactory.identifier3("i"); | |
| 1616 operand.staticType = numType; | |
| 1617 PrefixExpression expression = | |
| 1618 AstFactory.prefixExpression(TokenType.PLUS_PLUS, operand); | |
| 1619 _resolveNode(expression); | |
| 1620 expect(expression.staticElement, getMethod(numType, "+")); | |
| 1621 _listener.assertNoErrors(); | |
| 1622 } | |
| 1623 | |
| 1624 void test_visitPrefixedIdentifier_dynamic() { | 1631 void test_visitPrefixedIdentifier_dynamic() { |
| 1625 DartType dynamicType = _typeProvider.dynamicType; | 1632 DartType dynamicType = _typeProvider.dynamicType; |
| 1626 SimpleIdentifier target = AstFactory.identifier3("a"); | 1633 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 1627 VariableElementImpl variable = ElementFactory.localVariableElement(target); | 1634 VariableElementImpl variable = ElementFactory.localVariableElement(target); |
| 1628 variable.type = dynamicType; | 1635 variable.type = dynamicType; |
| 1629 target.staticElement = variable; | 1636 target.staticElement = variable; |
| 1630 target.staticType = dynamicType; | 1637 target.staticType = dynamicType; |
| 1631 PrefixedIdentifier identifier = | 1638 PrefixedIdentifier identifier = |
| 1632 AstFactory.identifier(target, AstFactory.identifier3("b")); | 1639 AstFactory.identifier(target, AstFactory.identifier3("b")); |
| 1633 _resolveNode(identifier); | 1640 _resolveNode(identifier); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1724 identifier, | 1731 identifier, |
| 1725 TokenType.EQ, | 1732 TokenType.EQ, |
| 1726 AstFactory.nullLiteral()); | 1733 AstFactory.nullLiteral()); |
| 1727 // resolve | 1734 // resolve |
| 1728 _resolveNode(identifier); | 1735 _resolveNode(identifier); |
| 1729 expect(identifier.staticElement, same(setter)); | 1736 expect(identifier.staticElement, same(setter)); |
| 1730 expect(identifier.identifier.staticElement, same(setter)); | 1737 expect(identifier.identifier.staticElement, same(setter)); |
| 1731 _listener.assertNoErrors(); | 1738 _listener.assertNoErrors(); |
| 1732 } | 1739 } |
| 1733 | 1740 |
| 1741 void test_visitPrefixExpression() { |
| 1742 InterfaceType numType = _typeProvider.numType; |
| 1743 SimpleIdentifier operand = AstFactory.identifier3("i"); |
| 1744 operand.staticType = numType; |
| 1745 PrefixExpression expression = |
| 1746 AstFactory.prefixExpression(TokenType.PLUS_PLUS, operand); |
| 1747 _resolveNode(expression); |
| 1748 expect(expression.staticElement, getMethod(numType, "+")); |
| 1749 _listener.assertNoErrors(); |
| 1750 } |
| 1751 |
| 1734 void test_visitPropertyAccess_getter_identifier() { | 1752 void test_visitPropertyAccess_getter_identifier() { |
| 1735 ClassElementImpl classA = ElementFactory.classElement2("A"); | 1753 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1736 String getterName = "b"; | 1754 String getterName = "b"; |
| 1737 PropertyAccessorElement getter = | 1755 PropertyAccessorElement getter = |
| 1738 ElementFactory.getterElement(getterName, false, _typeProvider.intType); | 1756 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 1739 classA.accessors = <PropertyAccessorElement>[getter]; | 1757 classA.accessors = <PropertyAccessorElement>[getter]; |
| 1740 SimpleIdentifier target = AstFactory.identifier3("a"); | 1758 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 1741 target.staticType = classA.type; | 1759 target.staticType = classA.type; |
| 1742 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); | 1760 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); |
| 1743 _resolveNode(access); | 1761 _resolveNode(access); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 try { | 1920 try { |
| 1903 return _visitor.elementResolver_J2DAccessor as ElementResolver; | 1921 return _visitor.elementResolver_J2DAccessor as ElementResolver; |
| 1904 } catch (exception) { | 1922 } catch (exception) { |
| 1905 throw new IllegalArgumentException( | 1923 throw new IllegalArgumentException( |
| 1906 "Could not create resolver", | 1924 "Could not create resolver", |
| 1907 exception); | 1925 exception); |
| 1908 } | 1926 } |
| 1909 } | 1927 } |
| 1910 | 1928 |
| 1911 /** | 1929 /** |
| 1912 * Return the element associated with the label of the given statement after t
he resolver has | 1930 * Return the element associated with the label of [statement] after the |
| 1913 * resolved the statement. | 1931 * resolver has resolved it. [labelElement] is the label element to be |
| 1914 * | 1932 * defined in the statement's label scope, and [labelTarget] is the statement |
| 1915 * @param statement the statement to be resolved | 1933 * the label resolves to. |
| 1916 * @param labelElement the label element to be defined in the statement's labe
l scope | |
| 1917 * @return the element to which the statement's label was resolved | |
| 1918 */ | 1934 */ |
| 1919 Element _resolveBreak(BreakStatement statement, | 1935 Element _resolveBreak(BreakStatement statement, LabelElementImpl labelElement, |
| 1920 LabelElementImpl labelElement) { | 1936 Statement labelTarget) { |
| 1921 _resolveStatement(statement, labelElement); | 1937 _resolveStatement(statement, labelElement, labelTarget); |
| 1922 return statement.label.staticElement; | 1938 return statement.label.staticElement; |
| 1923 } | 1939 } |
| 1924 | 1940 |
| 1925 /** | 1941 /** |
| 1926 * Return the element associated with the label of the given statement after t
he resolver has | 1942 * Return the element associated with the label [statement] after the |
| 1927 * resolved the statement. | 1943 * resolver has resolved it. [labelElement] is the label element to be |
| 1944 * defined in the statement's label scope, and [labelTarget] is the AST node |
| 1945 * the label resolves to. |
| 1928 * | 1946 * |
| 1929 * @param statement the statement to be resolved | 1947 * @param statement the statement to be resolved |
| 1930 * @param labelElement the label element to be defined in the statement's labe
l scope | 1948 * @param labelElement the label element to be defined in the statement's labe
l scope |
| 1931 * @return the element to which the statement's label was resolved | 1949 * @return the element to which the statement's label was resolved |
| 1932 */ | 1950 */ |
| 1933 Element _resolveContinue(ContinueStatement statement, | 1951 Element _resolveContinue(ContinueStatement statement, |
| 1934 LabelElementImpl labelElement) { | 1952 LabelElementImpl labelElement, AstNode labelTarget) { |
| 1935 _resolveStatement(statement, labelElement); | 1953 _resolveStatement(statement, labelElement, labelTarget); |
| 1936 return statement.label.staticElement; | 1954 return statement.label.staticElement; |
| 1937 } | 1955 } |
| 1938 | 1956 |
| 1939 /** | 1957 /** |
| 1940 * Return the element associated with the given identifier after the resolver
has resolved the | 1958 * Return the element associated with the given identifier after the resolver
has resolved the |
| 1941 * identifier. | 1959 * identifier. |
| 1942 * | 1960 * |
| 1943 * @param node the expression to be resolved | 1961 * @param node the expression to be resolved |
| 1944 * @param definedElements the elements that are to be defined in the scope in
which the element is | 1962 * @param definedElements the elements that are to be defined in the scope in
which the element is |
| 1945 * being resolved | 1963 * being resolved |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 } | 2040 } |
| 2023 | 2041 |
| 2024 /** | 2042 /** |
| 2025 * Return the element associated with the label of the given statement after t
he resolver has | 2043 * Return the element associated with the label of the given statement after t
he resolver has |
| 2026 * resolved the statement. | 2044 * resolved the statement. |
| 2027 * | 2045 * |
| 2028 * @param statement the statement to be resolved | 2046 * @param statement the statement to be resolved |
| 2029 * @param labelElement the label element to be defined in the statement's labe
l scope | 2047 * @param labelElement the label element to be defined in the statement's labe
l scope |
| 2030 * @return the element to which the statement's label was resolved | 2048 * @return the element to which the statement's label was resolved |
| 2031 */ | 2049 */ |
| 2032 void _resolveStatement(Statement statement, LabelElementImpl labelElement) { | 2050 void _resolveStatement(Statement statement, LabelElementImpl labelElement, |
| 2051 AstNode labelTarget) { |
| 2033 try { | 2052 try { |
| 2034 LabelScope outerScope = _visitor.labelScope_J2DAccessor as LabelScope; | 2053 LabelScope outerScope = _visitor.labelScope_J2DAccessor as LabelScope; |
| 2035 try { | 2054 try { |
| 2036 LabelScope innerScope; | 2055 LabelScope innerScope; |
| 2037 if (labelElement == null) { | 2056 if (labelElement == null) { |
| 2038 innerScope = new LabelScope.con1(outerScope, false, false); | 2057 innerScope = outerScope; |
| 2039 } else { | 2058 } else { |
| 2040 innerScope = | 2059 innerScope = |
| 2041 new LabelScope.con2(outerScope, labelElement.name, labelElement); | 2060 new LabelScope(outerScope, labelElement.name, labelTarget, labelEl
ement); |
| 2042 } | 2061 } |
| 2043 _visitor.labelScope_J2DAccessor = innerScope; | 2062 _visitor.labelScope_J2DAccessor = innerScope; |
| 2044 statement.accept(_resolver); | 2063 statement.accept(_resolver); |
| 2045 } finally { | 2064 } finally { |
| 2046 _visitor.labelScope_J2DAccessor = outerScope; | 2065 _visitor.labelScope_J2DAccessor = outerScope; |
| 2047 } | 2066 } |
| 2048 } catch (exception) { | 2067 } catch (exception) { |
| 2049 throw new IllegalArgumentException("Could not resolve node", exception); | 2068 throw new IllegalArgumentException("Could not resolve node", exception); |
| 2050 } | 2069 } |
| 2051 } | 2070 } |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2654 return; | 2673 return; |
| 2655 var two = 2; | 2674 var two = 2; |
| 2656 return; | 2675 return; |
| 2657 var three = 3; | 2676 var three = 3; |
| 2658 }'''); | 2677 }'''); |
| 2659 resolve(source); | 2678 resolve(source); |
| 2660 assertErrors(source, [HintCode.DEAD_CODE]); | 2679 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2661 verify([source]); | 2680 verify([source]); |
| 2662 } | 2681 } |
| 2663 | 2682 |
| 2664 void test_deprecatedAnnotationUse_Deprecated() { | |
| 2665 Source source = addSource(r''' | |
| 2666 class A { | |
| 2667 @Deprecated('0.9') | |
| 2668 m() {} | |
| 2669 n() {m();} | |
| 2670 }'''); | |
| 2671 resolve(source); | |
| 2672 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | |
| 2673 verify([source]); | |
| 2674 } | |
| 2675 | |
| 2676 void test_deprecatedAnnotationUse_assignment() { | 2683 void test_deprecatedAnnotationUse_assignment() { |
| 2677 Source source = addSource(r''' | 2684 Source source = addSource(r''' |
| 2678 class A { | 2685 class A { |
| 2679 @deprecated | 2686 @deprecated |
| 2680 A operator+(A a) { return a; } | 2687 A operator+(A a) { return a; } |
| 2681 } | 2688 } |
| 2682 f(A a) { | 2689 f(A a) { |
| 2683 A b; | 2690 A b; |
| 2684 a += b; | 2691 a += b; |
| 2685 }'''); | 2692 }'''); |
| 2686 resolve(source); | 2693 resolve(source); |
| 2687 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2694 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2695 verify([source]); |
| 2696 } |
| 2697 |
| 2698 void test_deprecatedAnnotationUse_Deprecated() { |
| 2699 Source source = addSource(r''' |
| 2700 class A { |
| 2701 @Deprecated('0.9') |
| 2702 m() {} |
| 2703 n() {m();} |
| 2704 }'''); |
| 2705 resolve(source); |
| 2706 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2688 verify([source]); | 2707 verify([source]); |
| 2689 } | 2708 } |
| 2690 | 2709 |
| 2691 void test_deprecatedAnnotationUse_deprecated() { | 2710 void test_deprecatedAnnotationUse_deprecated() { |
| 2692 Source source = addSource(r''' | 2711 Source source = addSource(r''' |
| 2693 class A { | 2712 class A { |
| 2694 @deprecated | 2713 @deprecated |
| 2695 m() {} | 2714 m() {} |
| 2696 n() {m();} | 2715 n() {m();} |
| 2697 }'''); | 2716 }'''); |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3598 _f(int p) { | 3617 _f(int p) { |
| 3599 _f(p - 1); | 3618 _f(p - 1); |
| 3600 } | 3619 } |
| 3601 main() { | 3620 main() { |
| 3602 }'''); | 3621 }'''); |
| 3603 resolve(source); | 3622 resolve(source); |
| 3604 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3623 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3605 verify([source]); | 3624 verify([source]); |
| 3606 } | 3625 } |
| 3607 | 3626 |
| 3627 void test_unusedElement_getter_isUsed_invocation_implicitThis() { |
| 3628 enableUnusedElement = true; |
| 3629 Source source = addSource(r''' |
| 3630 class A { |
| 3631 get _g => null; |
| 3632 useGetter() { |
| 3633 var v = _g; |
| 3634 } |
| 3635 }'''); |
| 3636 resolve(source); |
| 3637 assertNoErrors(source); |
| 3638 verify([source]); |
| 3639 } |
| 3640 |
| 3608 void test_unusedElement_getter_isUsed_invocation_PrefixedIdentifier() { | 3641 void test_unusedElement_getter_isUsed_invocation_PrefixedIdentifier() { |
| 3609 enableUnusedElement = true; | 3642 enableUnusedElement = true; |
| 3610 Source source = addSource(r''' | 3643 Source source = addSource(r''' |
| 3611 class A { | 3644 class A { |
| 3612 get _g => null; | 3645 get _g => null; |
| 3613 } | 3646 } |
| 3614 main(A a) { | 3647 main(A a) { |
| 3615 var v = a._g; | 3648 var v = a._g; |
| 3616 } | 3649 } |
| 3617 '''); | 3650 '''); |
| 3618 resolve(source); | 3651 resolve(source); |
| 3619 assertNoErrors(source); | |
| 3620 verify([source]); | |
| 3621 } | |
| 3622 | |
| 3623 void test_unusedElement_getter_isUsed_invocation_PropertyAccess() { | |
| 3624 enableUnusedElement = true; | |
| 3625 Source source = addSource(r''' | |
| 3626 class A { | |
| 3627 get _g => null; | |
| 3628 } | |
| 3629 main() { | |
| 3630 var v = new A()._g; | |
| 3631 } | |
| 3632 '''); | |
| 3633 resolve(source); | |
| 3634 assertNoErrors(source); | 3652 assertNoErrors(source); |
| 3635 verify([source]); | 3653 verify([source]); |
| 3636 } | 3654 } |
| 3637 | 3655 |
| 3638 void test_unusedElement_getter_isUsed_invocation_implicitThis() { | 3656 void test_unusedElement_getter_isUsed_invocation_PropertyAccess() { |
| 3639 enableUnusedElement = true; | 3657 enableUnusedElement = true; |
| 3640 Source source = addSource(r''' | 3658 Source source = addSource(r''' |
| 3641 class A { | 3659 class A { |
| 3642 get _g => null; | 3660 get _g => null; |
| 3643 useGetter() { | 3661 } |
| 3644 var v = _g; | 3662 main() { |
| 3645 } | 3663 var v = new A()._g; |
| 3646 }'''); | 3664 } |
| 3665 '''); |
| 3647 resolve(source); | 3666 resolve(source); |
| 3648 assertNoErrors(source); | 3667 assertNoErrors(source); |
| 3649 verify([source]); | 3668 verify([source]); |
| 3650 } | 3669 } |
| 3651 | 3670 |
| 3652 void test_unusedElement_getter_notUsed_noReference() { | 3671 void test_unusedElement_getter_notUsed_noReference() { |
| 3653 enableUnusedElement = true; | 3672 enableUnusedElement = true; |
| 3654 Source source = addSource(r''' | 3673 Source source = addSource(r''' |
| 3655 class A { | 3674 class A { |
| 3656 get _g => null; | 3675 get _g => null; |
| 3657 }'''); | 3676 }'''); |
| 3658 resolve(source); | 3677 resolve(source); |
| 3659 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3678 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3660 verify([source]); | 3679 verify([source]); |
| 3661 } | 3680 } |
| 3662 | 3681 |
| 3663 void test_unusedElement_getter_notUsed_referenceFromItself() { | 3682 void test_unusedElement_getter_notUsed_referenceFromItself() { |
| 3664 enableUnusedElement = true; | 3683 enableUnusedElement = true; |
| 3665 Source source = addSource(r''' | 3684 Source source = addSource(r''' |
| 3666 class A { | 3685 class A { |
| 3667 get _g { | 3686 get _g { |
| 3668 return _g; | 3687 return _g; |
| 3669 } | 3688 } |
| 3670 }'''); | 3689 }'''); |
| 3671 resolve(source); | 3690 resolve(source); |
| 3672 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3691 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3673 verify([source]); | 3692 verify([source]); |
| 3674 } | 3693 } |
| 3675 | 3694 |
| 3676 void test_unusedElement_method_isUsed_hasReference_PrefixedIdentifier() { | |
| 3677 enableUnusedElement = true; | |
| 3678 Source source = addSource(r''' | |
| 3679 class A { | |
| 3680 _m() {} | |
| 3681 } | |
| 3682 main(A a) { | |
| 3683 a._m; | |
| 3684 }'''); | |
| 3685 resolve(source); | |
| 3686 assertNoErrors(source); | |
| 3687 verify([source]); | |
| 3688 } | |
| 3689 | |
| 3690 void test_unusedElement_method_isUsed_hasReference_PropertyAccess() { | |
| 3691 enableUnusedElement = true; | |
| 3692 Source source = addSource(r''' | |
| 3693 class A { | |
| 3694 _m() {} | |
| 3695 } | |
| 3696 main() { | |
| 3697 new A()._m; | |
| 3698 }'''); | |
| 3699 resolve(source); | |
| 3700 assertNoErrors(source); | |
| 3701 verify([source]); | |
| 3702 } | |
| 3703 | |
| 3704 void test_unusedElement_method_isUsed_hasReference_implicitThis() { | 3695 void test_unusedElement_method_isUsed_hasReference_implicitThis() { |
| 3705 enableUnusedElement = true; | 3696 enableUnusedElement = true; |
| 3706 Source source = addSource(r''' | 3697 Source source = addSource(r''' |
| 3707 class A { | 3698 class A { |
| 3699 _m() {} |
| 3700 useMethod() { |
| 3701 print(_m); |
| 3702 } |
| 3703 } |
| 3704 print(x) {} |
| 3705 '''); |
| 3706 resolve(source); |
| 3707 assertNoErrors(source); |
| 3708 verify([source]); |
| 3709 } |
| 3710 |
| 3711 void test_unusedElement_method_isUsed_hasReference_implicitThis_subclass() { |
| 3712 enableUnusedElement = true; |
| 3713 Source source = addSource(r''' |
| 3714 class A { |
| 3708 _m() {} | 3715 _m() {} |
| 3709 useMethod() { | 3716 useMethod() { |
| 3710 print(_m); | 3717 print(_m); |
| 3711 } | 3718 } |
| 3712 } | 3719 } |
| 3720 class B extends A { |
| 3721 _m() {} |
| 3722 } |
| 3713 print(x) {} | 3723 print(x) {} |
| 3714 '''); | 3724 '''); |
| 3715 resolve(source); | 3725 resolve(source); |
| 3716 assertNoErrors(source); | 3726 assertNoErrors(source); |
| 3717 verify([source]); | 3727 verify([source]); |
| 3718 } | 3728 } |
| 3719 | 3729 |
| 3720 void test_unusedElement_method_isUsed_hasReference_implicitThis_subclass() { | 3730 void test_unusedElement_method_isUsed_hasReference_PrefixedIdentifier() { |
| 3721 enableUnusedElement = true; | 3731 enableUnusedElement = true; |
| 3722 Source source = addSource(r''' | 3732 Source source = addSource(r''' |
| 3723 class A { | 3733 class A { |
| 3724 _m() {} | 3734 _m() {} |
| 3725 useMethod() { | |
| 3726 print(_m); | |
| 3727 } | |
| 3728 } | 3735 } |
| 3729 class B extends A { | 3736 main(A a) { |
| 3730 _m() {} | 3737 a._m; |
| 3731 } | 3738 }'''); |
| 3732 print(x) {} | |
| 3733 '''); | |
| 3734 resolve(source); | 3739 resolve(source); |
| 3735 assertNoErrors(source); | 3740 assertNoErrors(source); |
| 3736 verify([source]); | 3741 verify([source]); |
| 3737 } | 3742 } |
| 3738 | 3743 |
| 3739 void test_unusedElement_method_isUsed_invocation_MemberElement() { | 3744 void test_unusedElement_method_isUsed_hasReference_PropertyAccess() { |
| 3740 enableUnusedElement = true; | 3745 enableUnusedElement = true; |
| 3741 Source source = addSource(r''' | 3746 Source source = addSource(r''' |
| 3742 class A<T> { | 3747 class A { |
| 3743 _m(T t) {} | 3748 _m() {} |
| 3744 } | 3749 } |
| 3745 main(A<int> a) { | 3750 main() { |
| 3746 a._m(0); | 3751 new A()._m; |
| 3747 }'''); | 3752 }'''); |
| 3748 resolve(source); | 3753 resolve(source); |
| 3749 assertNoErrors(source); | 3754 assertNoErrors(source); |
| 3750 verify([source]); | 3755 verify([source]); |
| 3751 } | 3756 } |
| 3752 | 3757 |
| 3753 void test_unusedElement_method_isUsed_invocation_implicitThis() { | 3758 void test_unusedElement_method_isUsed_invocation_implicitThis() { |
| 3754 enableUnusedElement = true; | 3759 enableUnusedElement = true; |
| 3755 Source source = addSource(r''' | 3760 Source source = addSource(r''' |
| 3756 class A { | 3761 class A { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3774 } | 3779 } |
| 3775 } | 3780 } |
| 3776 class B extends A { | 3781 class B extends A { |
| 3777 _m() {} | 3782 _m() {} |
| 3778 }'''); | 3783 }'''); |
| 3779 resolve(source); | 3784 resolve(source); |
| 3780 assertNoErrors(source); | 3785 assertNoErrors(source); |
| 3781 verify([source]); | 3786 verify([source]); |
| 3782 } | 3787 } |
| 3783 | 3788 |
| 3789 void test_unusedElement_method_isUsed_invocation_MemberElement() { |
| 3790 enableUnusedElement = true; |
| 3791 Source source = addSource(r''' |
| 3792 class A<T> { |
| 3793 _m(T t) {} |
| 3794 } |
| 3795 main(A<int> a) { |
| 3796 a._m(0); |
| 3797 }'''); |
| 3798 resolve(source); |
| 3799 assertNoErrors(source); |
| 3800 verify([source]); |
| 3801 } |
| 3802 |
| 3784 void test_unusedElement_method_isUsed_invocation_propagated() { | 3803 void test_unusedElement_method_isUsed_invocation_propagated() { |
| 3785 enableUnusedElement = true; | 3804 enableUnusedElement = true; |
| 3786 Source source = addSource(r''' | 3805 Source source = addSource(r''' |
| 3787 class A { | 3806 class A { |
| 3788 _m() {} | 3807 _m() {} |
| 3789 } | 3808 } |
| 3790 main() { | 3809 main() { |
| 3791 var a = new A(); | 3810 var a = new A(); |
| 3792 a._m(); | 3811 a._m(); |
| 3793 }'''); | 3812 }'''); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3872 class A { | 3891 class A { |
| 3873 static _m(int p) { | 3892 static _m(int p) { |
| 3874 _m(p - 1); | 3893 _m(p - 1); |
| 3875 } | 3894 } |
| 3876 }'''); | 3895 }'''); |
| 3877 resolve(source); | 3896 resolve(source); |
| 3878 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3897 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3879 verify([source]); | 3898 verify([source]); |
| 3880 } | 3899 } |
| 3881 | 3900 |
| 3901 void test_unusedElement_setter_isUsed_invocation_implicitThis() { |
| 3902 enableUnusedElement = true; |
| 3903 Source source = addSource(r''' |
| 3904 class A { |
| 3905 set _s(x) {} |
| 3906 useSetter() { |
| 3907 _s = 42; |
| 3908 } |
| 3909 }'''); |
| 3910 resolve(source); |
| 3911 assertNoErrors(source); |
| 3912 verify([source]); |
| 3913 } |
| 3914 |
| 3882 void test_unusedElement_setter_isUsed_invocation_PrefixedIdentifier() { | 3915 void test_unusedElement_setter_isUsed_invocation_PrefixedIdentifier() { |
| 3883 enableUnusedElement = true; | 3916 enableUnusedElement = true; |
| 3884 Source source = addSource(r''' | 3917 Source source = addSource(r''' |
| 3885 class A { | 3918 class A { |
| 3886 set _s(x) {} | 3919 set _s(x) {} |
| 3887 } | 3920 } |
| 3888 main(A a) { | 3921 main(A a) { |
| 3889 a._s = 42; | 3922 a._s = 42; |
| 3890 } | 3923 } |
| 3891 '''); | 3924 '''); |
| 3892 resolve(source); | 3925 resolve(source); |
| 3893 assertNoErrors(source); | |
| 3894 verify([source]); | |
| 3895 } | |
| 3896 | |
| 3897 void test_unusedElement_setter_isUsed_invocation_PropertyAccess() { | |
| 3898 enableUnusedElement = true; | |
| 3899 Source source = addSource(r''' | |
| 3900 class A { | |
| 3901 set _s(x) {} | |
| 3902 } | |
| 3903 main() { | |
| 3904 new A()._s = 42; | |
| 3905 } | |
| 3906 '''); | |
| 3907 resolve(source); | |
| 3908 assertNoErrors(source); | 3926 assertNoErrors(source); |
| 3909 verify([source]); | 3927 verify([source]); |
| 3910 } | 3928 } |
| 3911 | 3929 |
| 3912 void test_unusedElement_setter_isUsed_invocation_implicitThis() { | 3930 void test_unusedElement_setter_isUsed_invocation_PropertyAccess() { |
| 3913 enableUnusedElement = true; | 3931 enableUnusedElement = true; |
| 3914 Source source = addSource(r''' | 3932 Source source = addSource(r''' |
| 3915 class A { | 3933 class A { |
| 3916 set _s(x) {} | 3934 set _s(x) {} |
| 3917 useSetter() { | 3935 } |
| 3918 _s = 42; | 3936 main() { |
| 3919 } | 3937 new A()._s = 42; |
| 3920 }'''); | 3938 } |
| 3939 '''); |
| 3921 resolve(source); | 3940 resolve(source); |
| 3922 assertNoErrors(source); | 3941 assertNoErrors(source); |
| 3923 verify([source]); | 3942 verify([source]); |
| 3924 } | 3943 } |
| 3925 | 3944 |
| 3926 void test_unusedElement_setter_notUsed_noReference() { | 3945 void test_unusedElement_setter_notUsed_noReference() { |
| 3927 enableUnusedElement = true; | 3946 enableUnusedElement = true; |
| 3928 Source source = addSource(r''' | 3947 Source source = addSource(r''' |
| 3929 class A { | 3948 class A { |
| 3930 set _s(x) {} | 3949 set _s(x) {} |
| (...skipping 3541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7472 if (operandType == null || operandType.isDynamic) { | 7491 if (operandType == null || operandType.isDynamic) { |
| 7473 return null; | 7492 return null; |
| 7474 } | 7493 } |
| 7475 return _checkResolved( | 7494 return _checkResolved( |
| 7476 node, | 7495 node, |
| 7477 node.staticElement, | 7496 node.staticElement, |
| 7478 (node) => node is MethodElement); | 7497 (node) => node is MethodElement); |
| 7479 } | 7498 } |
| 7480 | 7499 |
| 7481 @override | 7500 @override |
| 7501 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 7502 SimpleIdentifier prefix = node.prefix; |
| 7503 prefix.accept(this); |
| 7504 DartType prefixType = prefix.staticType; |
| 7505 if (prefixType == null || prefixType.isDynamic) { |
| 7506 return null; |
| 7507 } |
| 7508 return _checkResolved(node, node.staticElement, null); |
| 7509 } |
| 7510 |
| 7511 @override |
| 7482 Object visitPrefixExpression(PrefixExpression node) { | 7512 Object visitPrefixExpression(PrefixExpression node) { |
| 7483 node.visitChildren(this); | 7513 node.visitChildren(this); |
| 7484 if (!node.operator.isUserDefinableOperator) { | 7514 if (!node.operator.isUserDefinableOperator) { |
| 7485 return null; | 7515 return null; |
| 7486 } | 7516 } |
| 7487 DartType operandType = node.operand.staticType; | 7517 DartType operandType = node.operand.staticType; |
| 7488 if (operandType == null || operandType.isDynamic) { | 7518 if (operandType == null || operandType.isDynamic) { |
| 7489 return null; | 7519 return null; |
| 7490 } | 7520 } |
| 7491 return _checkResolved( | 7521 return _checkResolved( |
| 7492 node, | 7522 node, |
| 7493 node.staticElement, | 7523 node.staticElement, |
| 7494 (node) => node is MethodElement); | 7524 (node) => node is MethodElement); |
| 7495 } | 7525 } |
| 7496 | 7526 |
| 7497 @override | 7527 @override |
| 7498 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 7499 SimpleIdentifier prefix = node.prefix; | |
| 7500 prefix.accept(this); | |
| 7501 DartType prefixType = prefix.staticType; | |
| 7502 if (prefixType == null || prefixType.isDynamic) { | |
| 7503 return null; | |
| 7504 } | |
| 7505 return _checkResolved(node, node.staticElement, null); | |
| 7506 } | |
| 7507 | |
| 7508 @override | |
| 7509 Object visitPropertyAccess(PropertyAccess node) { | 7528 Object visitPropertyAccess(PropertyAccess node) { |
| 7510 Expression target = node.realTarget; | 7529 Expression target = node.realTarget; |
| 7511 target.accept(this); | 7530 target.accept(this); |
| 7512 DartType targetType = target.staticType; | 7531 DartType targetType = target.staticType; |
| 7513 if (targetType == null || targetType.isDynamic) { | 7532 if (targetType == null || targetType.isDynamic) { |
| 7514 return null; | 7533 return null; |
| 7515 } | 7534 } |
| 7516 return node.propertyName.accept(this); | 7535 return node.propertyName.accept(this); |
| 7517 } | 7536 } |
| 7518 | 7537 |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7904 * @return the source that was created | 7923 * @return the source that was created |
| 7905 */ | 7924 */ |
| 7906 FileBasedSource _createNamedSource(String fileName) { | 7925 FileBasedSource _createNamedSource(String fileName) { |
| 7907 FileBasedSource source = | 7926 FileBasedSource source = |
| 7908 new FileBasedSource.con1(FileUtilities2.createFile(fileName)); | 7927 new FileBasedSource.con1(FileUtilities2.createFile(fileName)); |
| 7909 analysisContext2.setContents(source, ""); | 7928 analysisContext2.setContents(source, ""); |
| 7910 return source; | 7929 return source; |
| 7911 } | 7930 } |
| 7912 } | 7931 } |
| 7913 | 7932 |
| 7933 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope { |
| 7934 GatheringErrorListener listener; |
| 7935 |
| 7936 Scope_EnclosedScopeTest_test_define_duplicate(this.listener) : super(); |
| 7937 |
| 7938 @override |
| 7939 AnalysisErrorListener get errorListener => listener; |
| 7940 |
| 7941 @override |
| 7942 Element internalLookup(Identifier identifier, String name, |
| 7943 LibraryElement referencingLibrary) => |
| 7944 null; |
| 7945 } |
| 7946 |
| 7947 class Scope_EnclosedScopeTest_test_define_normal extends Scope { |
| 7948 GatheringErrorListener listener; |
| 7949 |
| 7950 Scope_EnclosedScopeTest_test_define_normal(this.listener) : super(); |
| 7951 |
| 7952 @override |
| 7953 AnalysisErrorListener get errorListener => listener; |
| 7954 |
| 7955 @override |
| 7956 Element internalLookup(Identifier identifier, String name, |
| 7957 LibraryElement referencingLibrary) => |
| 7958 null; |
| 7959 } |
| 7960 |
| 7914 class ScopeTest extends ResolverTestCase { | 7961 class ScopeTest extends ResolverTestCase { |
| 7915 void test_define_duplicate() { | 7962 void test_define_duplicate() { |
| 7916 GatheringErrorListener errorListener = new GatheringErrorListener(); | 7963 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 7917 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); | 7964 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); |
| 7918 VariableElement element1 = | 7965 VariableElement element1 = |
| 7919 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); | 7966 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); |
| 7920 VariableElement element2 = | 7967 VariableElement element2 = |
| 7921 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); | 7968 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); |
| 7922 scope.define(element1); | 7969 scope.define(element1); |
| 7923 scope.define(element2); | 7970 scope.define(element2); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7961 final AnalysisErrorListener errorListener; | 8008 final AnalysisErrorListener errorListener; |
| 7962 | 8009 |
| 7963 ScopeTest_TestScope(this.errorListener); | 8010 ScopeTest_TestScope(this.errorListener); |
| 7964 | 8011 |
| 7965 @override | 8012 @override |
| 7966 Element internalLookup(Identifier identifier, String name, | 8013 Element internalLookup(Identifier identifier, String name, |
| 7967 LibraryElement referencingLibrary) => | 8014 LibraryElement referencingLibrary) => |
| 7968 localLookup(name, referencingLibrary); | 8015 localLookup(name, referencingLibrary); |
| 7969 } | 8016 } |
| 7970 | 8017 |
| 7971 class Scope_EnclosedScopeTest_test_define_duplicate extends Scope { | |
| 7972 GatheringErrorListener listener; | |
| 7973 | |
| 7974 Scope_EnclosedScopeTest_test_define_duplicate(this.listener) : super(); | |
| 7975 | |
| 7976 @override | |
| 7977 AnalysisErrorListener get errorListener => listener; | |
| 7978 | |
| 7979 @override | |
| 7980 Element internalLookup(Identifier identifier, String name, | |
| 7981 LibraryElement referencingLibrary) => | |
| 7982 null; | |
| 7983 } | |
| 7984 | |
| 7985 class Scope_EnclosedScopeTest_test_define_normal extends Scope { | |
| 7986 GatheringErrorListener listener; | |
| 7987 | |
| 7988 Scope_EnclosedScopeTest_test_define_normal(this.listener) : super(); | |
| 7989 | |
| 7990 @override | |
| 7991 AnalysisErrorListener get errorListener => listener; | |
| 7992 | |
| 7993 @override | |
| 7994 Element internalLookup(Identifier identifier, String name, | |
| 7995 LibraryElement referencingLibrary) => | |
| 7996 null; | |
| 7997 } | |
| 7998 | |
| 7999 class SimpleResolverTest extends ResolverTestCase { | 8018 class SimpleResolverTest extends ResolverTestCase { |
| 8000 void fail_staticInvocation() { | 8019 void fail_staticInvocation() { |
| 8001 Source source = addSource(r''' | 8020 Source source = addSource(r''' |
| 8002 class A { | 8021 class A { |
| 8003 static int get g => (a,b) => 0; | 8022 static int get g => (a,b) => 0; |
| 8004 } | 8023 } |
| 8005 class B { | 8024 class B { |
| 8006 f() { | 8025 f() { |
| 8007 A.g(1,0); | 8026 A.g(1,0); |
| 8008 } | 8027 } |
| 8009 }'''); | 8028 }'''); |
| 8010 resolve(source); | 8029 resolve(source); |
| 8011 assertNoErrors(source); | 8030 assertNoErrors(source); |
| 8012 verify([source]); | 8031 verify([source]); |
| 8013 } | 8032 } |
| 8014 | 8033 |
| 8034 void test_argumentResolution_required_matching() { |
| 8035 Source source = addSource(r''' |
| 8036 class A { |
| 8037 void f() { |
| 8038 g(1, 2, 3); |
| 8039 } |
| 8040 void g(a, b, c) {} |
| 8041 }'''); |
| 8042 _validateArgumentResolution(source, [0, 1, 2]); |
| 8043 } |
| 8044 |
| 8045 void test_argumentResolution_required_tooFew() { |
| 8046 Source source = addSource(r''' |
| 8047 class A { |
| 8048 void f() { |
| 8049 g(1, 2); |
| 8050 } |
| 8051 void g(a, b, c) {} |
| 8052 }'''); |
| 8053 _validateArgumentResolution(source, [0, 1]); |
| 8054 } |
| 8055 |
| 8056 void test_argumentResolution_required_tooMany() { |
| 8057 Source source = addSource(r''' |
| 8058 class A { |
| 8059 void f() { |
| 8060 g(1, 2, 3); |
| 8061 } |
| 8062 void g(a, b) {} |
| 8063 }'''); |
| 8064 _validateArgumentResolution(source, [0, 1, -1]); |
| 8065 } |
| 8066 |
| 8015 void test_argumentResolution_requiredAndNamed_extra() { | 8067 void test_argumentResolution_requiredAndNamed_extra() { |
| 8016 Source source = addSource(r''' | 8068 Source source = addSource(r''' |
| 8017 class A { | 8069 class A { |
| 8018 void f() { | 8070 void f() { |
| 8019 g(1, 2, c: 3, d: 4); | 8071 g(1, 2, c: 3, d: 4); |
| 8020 } | 8072 } |
| 8021 void g(a, b, {c}) {} | 8073 void g(a, b, {c}) {} |
| 8022 }'''); | 8074 }'''); |
| 8023 _validateArgumentResolution(source, [0, 1, 2, -1]); | 8075 _validateArgumentResolution(source, [0, 1, 2, -1]); |
| 8024 } | 8076 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8071 Source source = addSource(r''' | 8123 Source source = addSource(r''' |
| 8072 class A { | 8124 class A { |
| 8073 void f() { | 8125 void f() { |
| 8074 g(1, 2, 3, 4); | 8126 g(1, 2, 3, 4); |
| 8075 } | 8127 } |
| 8076 void g(a, b, [c]) {} | 8128 void g(a, b, [c]) {} |
| 8077 }'''); | 8129 }'''); |
| 8078 _validateArgumentResolution(source, [0, 1, 2, -1]); | 8130 _validateArgumentResolution(source, [0, 1, 2, -1]); |
| 8079 } | 8131 } |
| 8080 | 8132 |
| 8081 void test_argumentResolution_required_matching() { | |
| 8082 Source source = addSource(r''' | |
| 8083 class A { | |
| 8084 void f() { | |
| 8085 g(1, 2, 3); | |
| 8086 } | |
| 8087 void g(a, b, c) {} | |
| 8088 }'''); | |
| 8089 _validateArgumentResolution(source, [0, 1, 2]); | |
| 8090 } | |
| 8091 | |
| 8092 void test_argumentResolution_required_tooFew() { | |
| 8093 Source source = addSource(r''' | |
| 8094 class A { | |
| 8095 void f() { | |
| 8096 g(1, 2); | |
| 8097 } | |
| 8098 void g(a, b, c) {} | |
| 8099 }'''); | |
| 8100 _validateArgumentResolution(source, [0, 1]); | |
| 8101 } | |
| 8102 | |
| 8103 void test_argumentResolution_required_tooMany() { | |
| 8104 Source source = addSource(r''' | |
| 8105 class A { | |
| 8106 void f() { | |
| 8107 g(1, 2, 3); | |
| 8108 } | |
| 8109 void g(a, b) {} | |
| 8110 }'''); | |
| 8111 _validateArgumentResolution(source, [0, 1, -1]); | |
| 8112 } | |
| 8113 | |
| 8114 void test_argumentResolution_setter_propagated() { | 8133 void test_argumentResolution_setter_propagated() { |
| 8115 Source source = addSource(r''' | 8134 Source source = addSource(r''' |
| 8116 main() { | 8135 main() { |
| 8117 var a = new A(); | 8136 var a = new A(); |
| 8118 a.sss = 0; | 8137 a.sss = 0; |
| 8119 } | 8138 } |
| 8120 class A { | 8139 class A { |
| 8121 set sss(x) {} | 8140 set sss(x) {} |
| 8122 }'''); | 8141 }'''); |
| 8123 LibraryElement library = resolve(source); | 8142 LibraryElement library = resolve(source); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8240 Expression rhs = assignment.rightHandSide; | 8259 Expression rhs = assignment.rightHandSide; |
| 8241 ParameterElement parameter = rhs.staticParameterElement; | 8260 ParameterElement parameter = rhs.staticParameterElement; |
| 8242 expect(parameter, isNotNull); | 8261 expect(parameter, isNotNull); |
| 8243 expect(parameter.displayName, "x"); | 8262 expect(parameter.displayName, "x"); |
| 8244 // validate | 8263 // validate |
| 8245 ClassElement classB = unit.types[1]; | 8264 ClassElement classB = unit.types[1]; |
| 8246 PropertyAccessorElement setter = classB.accessors[0]; | 8265 PropertyAccessorElement setter = classB.accessors[0]; |
| 8247 expect(setter.parameters[0], same(parameter)); | 8266 expect(setter.parameters[0], same(parameter)); |
| 8248 } | 8267 } |
| 8249 | 8268 |
| 8269 void test_breakTarget_labeled() { |
| 8270 // Verify that the target of the label is correctly found and is recorded |
| 8271 // as the unlabeled portion of the statement. |
| 8272 String text = r''' |
| 8273 void f() { |
| 8274 loop1: while (true) { |
| 8275 loop2: for (int i = 0; i < 10; i++) { |
| 8276 break loop1; |
| 8277 break loop2; |
| 8278 } |
| 8279 } |
| 8280 } |
| 8281 '''; |
| 8282 CompilationUnit unit = resolveSource(text); |
| 8283 WhileStatement whileStatement = EngineTestCase.findNode( |
| 8284 unit, |
| 8285 text, |
| 8286 'while (true)', |
| 8287 (n) => n is WhileStatement); |
| 8288 ForStatement forStatement = |
| 8289 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 8290 BreakStatement break1 = |
| 8291 EngineTestCase.findNode(unit, text, 'break loop1', (n) => n is BreakStat
ement); |
| 8292 BreakStatement break2 = |
| 8293 EngineTestCase.findNode(unit, text, 'break loop2', (n) => n is BreakStat
ement); |
| 8294 expect(break1.target, same(whileStatement)); |
| 8295 expect(break2.target, same(forStatement)); |
| 8296 } |
| 8297 |
| 8298 void test_breakTarget_unlabeledBreakFromDo() { |
| 8299 String text = r''' |
| 8300 void f() { |
| 8301 do { |
| 8302 break; |
| 8303 } while (true); |
| 8304 } |
| 8305 '''; |
| 8306 CompilationUnit unit = resolveSource(text); |
| 8307 DoStatement doStatement = |
| 8308 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); |
| 8309 BreakStatement breakStatement = |
| 8310 EngineTestCase.findNode(unit, text, 'break', (n) => n is BreakStatement)
; |
| 8311 expect(breakStatement.target, same(doStatement)); |
| 8312 } |
| 8313 |
| 8314 void test_breakTarget_unlabeledBreakFromFor() { |
| 8315 String text = r''' |
| 8316 void f() { |
| 8317 for (int i = 0; i < 10; i++) { |
| 8318 break; |
| 8319 } |
| 8320 } |
| 8321 '''; |
| 8322 CompilationUnit unit = resolveSource(text); |
| 8323 ForStatement forStatement = |
| 8324 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 8325 BreakStatement breakStatement = |
| 8326 EngineTestCase.findNode(unit, text, 'break', (n) => n is BreakStatement)
; |
| 8327 expect(breakStatement.target, same(forStatement)); |
| 8328 } |
| 8329 |
| 8330 void test_breakTarget_unlabeledBreakFromForEach() { |
| 8331 String text = r''' |
| 8332 void f() { |
| 8333 for (x in []) { |
| 8334 break; |
| 8335 } |
| 8336 } |
| 8337 '''; |
| 8338 CompilationUnit unit = resolveSource(text); |
| 8339 ForEachStatement forStatement = |
| 8340 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForEachStatement)
; |
| 8341 BreakStatement breakStatement = |
| 8342 EngineTestCase.findNode(unit, text, 'break', (n) => n is BreakStatement)
; |
| 8343 expect(breakStatement.target, same(forStatement)); |
| 8344 } |
| 8345 |
| 8346 void test_breakTarget_unlabeledBreakFromSwitch() { |
| 8347 String text = r''' |
| 8348 void f() { |
| 8349 while (true) { |
| 8350 switch (0) { |
| 8351 case 0: |
| 8352 break; |
| 8353 } |
| 8354 } |
| 8355 } |
| 8356 '''; |
| 8357 CompilationUnit unit = resolveSource(text); |
| 8358 SwitchStatement switchStatement = |
| 8359 EngineTestCase.findNode(unit, text, 'switch', (n) => n is SwitchStatemen
t); |
| 8360 BreakStatement breakStatement = |
| 8361 EngineTestCase.findNode(unit, text, 'break', (n) => n is BreakStatement)
; |
| 8362 expect(breakStatement.target, same(switchStatement)); |
| 8363 } |
| 8364 |
| 8365 void test_breakTarget_unlabeledBreakFromWhile() { |
| 8366 String text = r''' |
| 8367 void f() { |
| 8368 while (true) { |
| 8369 break; |
| 8370 } |
| 8371 } |
| 8372 '''; |
| 8373 CompilationUnit unit = resolveSource(text); |
| 8374 WhileStatement whileStatement = |
| 8375 EngineTestCase.findNode(unit, text, 'while', (n) => n is WhileStatement)
; |
| 8376 BreakStatement breakStatement = |
| 8377 EngineTestCase.findNode(unit, text, 'break', (n) => n is BreakStatement)
; |
| 8378 expect(breakStatement.target, same(whileStatement)); |
| 8379 } |
| 8380 |
| 8381 void test_breakTarget_unlabeledBreakToOuterFunction() { |
| 8382 // Verify that unlabeled break statements can't resolve to loops in an |
| 8383 // outer function. |
| 8384 String text = r''' |
| 8385 void f() { |
| 8386 while (true) { |
| 8387 void g() { |
| 8388 break; |
| 8389 } |
| 8390 } |
| 8391 } |
| 8392 '''; |
| 8393 CompilationUnit unit = resolveSource(text); |
| 8394 BreakStatement breakStatement = |
| 8395 EngineTestCase.findNode(unit, text, 'break', (n) => n is BreakStatement)
; |
| 8396 expect(breakStatement.target, isNull); |
| 8397 } |
| 8398 |
| 8250 void test_class_definesCall() { | 8399 void test_class_definesCall() { |
| 8251 Source source = addSource(r''' | 8400 Source source = addSource(r''' |
| 8252 class A { | 8401 class A { |
| 8253 int call(int x) { return x; } | 8402 int call(int x) { return x; } |
| 8254 } | 8403 } |
| 8255 int f(A a) { | 8404 int f(A a) { |
| 8256 return a(0); | 8405 return a(0); |
| 8257 }'''); | 8406 }'''); |
| 8258 resolve(source); | 8407 resolve(source); |
| 8259 assertNoErrors(source); | 8408 assertNoErrors(source); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8299 | 8448 |
| 8300 void test_commentReference_singleLine() { | 8449 void test_commentReference_singleLine() { |
| 8301 Source source = addSource(r''' | 8450 Source source = addSource(r''' |
| 8302 /// [A] | 8451 /// [A] |
| 8303 class A {}'''); | 8452 class A {}'''); |
| 8304 resolve(source); | 8453 resolve(source); |
| 8305 assertNoErrors(source); | 8454 assertNoErrors(source); |
| 8306 verify([source]); | 8455 verify([source]); |
| 8307 } | 8456 } |
| 8308 | 8457 |
| 8458 void test_continueTarget_labeled() { |
| 8459 // Verify that the target of the label is correctly found and is recorded |
| 8460 // as the unlabeled portion of the statement. |
| 8461 String text = r''' |
| 8462 void f() { |
| 8463 loop1: while (true) { |
| 8464 loop2: for (int i = 0; i < 10; i++) { |
| 8465 continue loop1; |
| 8466 continue loop2; |
| 8467 } |
| 8468 } |
| 8469 } |
| 8470 '''; |
| 8471 CompilationUnit unit = resolveSource(text); |
| 8472 WhileStatement whileStatement = EngineTestCase.findNode( |
| 8473 unit, |
| 8474 text, |
| 8475 'while (true)', |
| 8476 (n) => n is WhileStatement); |
| 8477 ForStatement forStatement = |
| 8478 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 8479 ContinueStatement continue1 = EngineTestCase.findNode( |
| 8480 unit, |
| 8481 text, |
| 8482 'continue loop1', |
| 8483 (n) => n is ContinueStatement); |
| 8484 ContinueStatement continue2 = EngineTestCase.findNode( |
| 8485 unit, |
| 8486 text, |
| 8487 'continue loop2', |
| 8488 (n) => n is ContinueStatement); |
| 8489 expect(continue1.target, same(whileStatement)); |
| 8490 expect(continue2.target, same(forStatement)); |
| 8491 } |
| 8492 |
| 8493 void test_continueTarget_unlabeledContinueFromDo() { |
| 8494 String text = r''' |
| 8495 void f() { |
| 8496 do { |
| 8497 continue; |
| 8498 } while (true); |
| 8499 } |
| 8500 '''; |
| 8501 CompilationUnit unit = resolveSource(text); |
| 8502 DoStatement doStatement = |
| 8503 EngineTestCase.findNode(unit, text, 'do', (n) => n is DoStatement); |
| 8504 ContinueStatement continueStatement = |
| 8505 EngineTestCase.findNode(unit, text, 'continue', (n) => n is ContinueStat
ement); |
| 8506 expect(continueStatement.target, same(doStatement)); |
| 8507 } |
| 8508 |
| 8509 void test_continueTarget_unlabeledContinueFromFor() { |
| 8510 String text = r''' |
| 8511 void f() { |
| 8512 for (int i = 0; i < 10; i++) { |
| 8513 continue; |
| 8514 } |
| 8515 } |
| 8516 '''; |
| 8517 CompilationUnit unit = resolveSource(text); |
| 8518 ForStatement forStatement = |
| 8519 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForStatement); |
| 8520 ContinueStatement continueStatement = |
| 8521 EngineTestCase.findNode(unit, text, 'continue', (n) => n is ContinueStat
ement); |
| 8522 expect(continueStatement.target, same(forStatement)); |
| 8523 } |
| 8524 |
| 8525 void test_continueTarget_unlabeledContinueFromForEach() { |
| 8526 String text = r''' |
| 8527 void f() { |
| 8528 for (x in []) { |
| 8529 continue; |
| 8530 } |
| 8531 } |
| 8532 '''; |
| 8533 CompilationUnit unit = resolveSource(text); |
| 8534 ForEachStatement forStatement = |
| 8535 EngineTestCase.findNode(unit, text, 'for', (n) => n is ForEachStatement)
; |
| 8536 ContinueStatement continueStatement = |
| 8537 EngineTestCase.findNode(unit, text, 'continue', (n) => n is ContinueStat
ement); |
| 8538 expect(continueStatement.target, same(forStatement)); |
| 8539 } |
| 8540 |
| 8541 void test_continueTarget_unlabeledContinueFromWhile() { |
| 8542 String text = r''' |
| 8543 void f() { |
| 8544 while (true) { |
| 8545 continue; |
| 8546 } |
| 8547 } |
| 8548 '''; |
| 8549 CompilationUnit unit = resolveSource(text); |
| 8550 WhileStatement whileStatement = |
| 8551 EngineTestCase.findNode(unit, text, 'while', (n) => n is WhileStatement)
; |
| 8552 ContinueStatement continueStatement = |
| 8553 EngineTestCase.findNode(unit, text, 'continue', (n) => n is ContinueStat
ement); |
| 8554 expect(continueStatement.target, same(whileStatement)); |
| 8555 } |
| 8556 |
| 8557 void test_continueTarget_unlabeledContinueSkipsSwitch() { |
| 8558 String text = r''' |
| 8559 void f() { |
| 8560 while (true) { |
| 8561 switch (0) { |
| 8562 case 0: |
| 8563 continue; |
| 8564 } |
| 8565 } |
| 8566 } |
| 8567 '''; |
| 8568 CompilationUnit unit = resolveSource(text); |
| 8569 WhileStatement whileStatement = |
| 8570 EngineTestCase.findNode(unit, text, 'while', (n) => n is WhileStatement)
; |
| 8571 ContinueStatement continueStatement = |
| 8572 EngineTestCase.findNode(unit, text, 'continue', (n) => n is ContinueStat
ement); |
| 8573 expect(continueStatement.target, same(whileStatement)); |
| 8574 } |
| 8575 |
| 8576 void test_continueTarget_unlabeledContinueToOuterFunction() { |
| 8577 // Verify that unlabeled continue statements can't resolve to loops in an |
| 8578 // outer function. |
| 8579 String text = r''' |
| 8580 void f() { |
| 8581 while (true) { |
| 8582 void g() { |
| 8583 continue; |
| 8584 } |
| 8585 } |
| 8586 } |
| 8587 '''; |
| 8588 CompilationUnit unit = resolveSource(text); |
| 8589 ContinueStatement continueStatement = |
| 8590 EngineTestCase.findNode(unit, text, 'continue', (n) => n is ContinueStat
ement); |
| 8591 expect(continueStatement.target, isNull); |
| 8592 } |
| 8593 |
| 8309 void test_empty() { | 8594 void test_empty() { |
| 8310 Source source = addSource(""); | 8595 Source source = addSource(""); |
| 8311 resolve(source); | 8596 resolve(source); |
| 8312 assertNoErrors(source); | 8597 assertNoErrors(source); |
| 8313 verify([source]); | 8598 verify([source]); |
| 8314 } | 8599 } |
| 8315 | 8600 |
| 8316 void test_entryPoint_exported() { | 8601 void test_entryPoint_exported() { |
| 8317 addNamedSource("/two.dart", r''' | 8602 addNamedSource("/two.dart", r''' |
| 8318 library two; | 8603 library two; |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8884 EngineTestCase.assertInstanceOf( | 9169 EngineTestCase.assertInstanceOf( |
| 8885 (obj) => obj is PropertyInducingElement, | 9170 (obj) => obj is PropertyInducingElement, |
| 8886 PropertyInducingElement, | 9171 PropertyInducingElement, |
| 8887 expectedElement); | 9172 expectedElement); |
| 8888 expectedElement = (expectedElement as PropertyInducingElement).getter; | 9173 expectedElement = (expectedElement as PropertyInducingElement).getter; |
| 8889 Element actualElement = | 9174 Element actualElement = |
| 8890 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement; | 9175 (declarations[1] as FunctionTypeAlias).metadata[0].name.staticElement; |
| 8891 expect(actualElement, same(expectedElement)); | 9176 expect(actualElement, same(expectedElement)); |
| 8892 } | 9177 } |
| 8893 | 9178 |
| 8894 void test_methodCascades() { | |
| 8895 Source source = addSource(r''' | |
| 8896 class A { | |
| 8897 void m1() {} | |
| 8898 void m2() {} | |
| 8899 void m() { | |
| 8900 A a = new A(); | |
| 8901 a..m1() | |
| 8902 ..m2(); | |
| 8903 } | |
| 8904 }'''); | |
| 8905 resolve(source); | |
| 8906 assertNoErrors(source); | |
| 8907 verify([source]); | |
| 8908 } | |
| 8909 | |
| 8910 void test_methodCascades_withSetter() { | |
| 8911 Source source = addSource(r''' | |
| 8912 class A { | |
| 8913 String name; | |
| 8914 void m1() {} | |
| 8915 void m2() {} | |
| 8916 void m() { | |
| 8917 A a = new A(); | |
| 8918 a..m1() | |
| 8919 ..name = 'name' | |
| 8920 ..m2(); | |
| 8921 } | |
| 8922 }'''); | |
| 8923 resolve(source); | |
| 8924 // failing with error code: INVOCATION_OF_NON_FUNCTION | |
| 8925 assertNoErrors(source); | |
| 8926 verify([source]); | |
| 8927 } | |
| 8928 | |
| 8929 void test_method_fromMixin() { | 9179 void test_method_fromMixin() { |
| 8930 Source source = addSource(r''' | 9180 Source source = addSource(r''' |
| 8931 class B { | 9181 class B { |
| 8932 bar() => 1; | 9182 bar() => 1; |
| 8933 } | 9183 } |
| 8934 class A { | 9184 class A { |
| 8935 foo() => 2; | 9185 foo() => 2; |
| 8936 } | 9186 } |
| 8937 | 9187 |
| 8938 class C extends B with A { | 9188 class C extends B with A { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 8954 class C extends B { | 9204 class C extends B { |
| 8955 } | 9205 } |
| 8956 f(C c) { | 9206 f(C c) { |
| 8957 c.m1(); | 9207 c.m1(); |
| 8958 }'''); | 9208 }'''); |
| 8959 resolve(source); | 9209 resolve(source); |
| 8960 assertNoErrors(source); | 9210 assertNoErrors(source); |
| 8961 verify([source]); | 9211 verify([source]); |
| 8962 } | 9212 } |
| 8963 | 9213 |
| 9214 void test_methodCascades() { |
| 9215 Source source = addSource(r''' |
| 9216 class A { |
| 9217 void m1() {} |
| 9218 void m2() {} |
| 9219 void m() { |
| 9220 A a = new A(); |
| 9221 a..m1() |
| 9222 ..m2(); |
| 9223 } |
| 9224 }'''); |
| 9225 resolve(source); |
| 9226 assertNoErrors(source); |
| 9227 verify([source]); |
| 9228 } |
| 9229 |
| 9230 void test_methodCascades_withSetter() { |
| 9231 Source source = addSource(r''' |
| 9232 class A { |
| 9233 String name; |
| 9234 void m1() {} |
| 9235 void m2() {} |
| 9236 void m() { |
| 9237 A a = new A(); |
| 9238 a..m1() |
| 9239 ..name = 'name' |
| 9240 ..m2(); |
| 9241 } |
| 9242 }'''); |
| 9243 resolve(source); |
| 9244 // failing with error code: INVOCATION_OF_NON_FUNCTION |
| 9245 assertNoErrors(source); |
| 9246 verify([source]); |
| 9247 } |
| 9248 |
| 8964 void test_resolveAgainstNull() { | 9249 void test_resolveAgainstNull() { |
| 8965 Source source = addSource(r''' | 9250 Source source = addSource(r''' |
| 8966 f(var p) { | 9251 f(var p) { |
| 8967 return null == p; | 9252 return null == p; |
| 8968 }'''); | 9253 }'''); |
| 8969 resolve(source); | 9254 resolve(source); |
| 8970 assertNoErrors(source); | 9255 assertNoErrors(source); |
| 8971 } | 9256 } |
| 8972 | 9257 |
| 8973 void test_setter_inherited() { | 9258 void test_setter_inherited() { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9284 // 2 / 2 | 9569 // 2 / 2 |
| 9285 BinaryExpression node = AstFactory.binaryExpression( | 9570 BinaryExpression node = AstFactory.binaryExpression( |
| 9286 _resolvedInteger(2), | 9571 _resolvedInteger(2), |
| 9287 TokenType.SLASH, | 9572 TokenType.SLASH, |
| 9288 _resolvedInteger(2)); | 9573 _resolvedInteger(2)); |
| 9289 node.staticElement = getMethod(_typeProvider.numType, "/"); | 9574 node.staticElement = getMethod(_typeProvider.numType, "/"); |
| 9290 expect(_analyze(node), same(_typeProvider.doubleType)); | 9575 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 9291 _listener.assertNoErrors(); | 9576 _listener.assertNoErrors(); |
| 9292 } | 9577 } |
| 9293 | 9578 |
| 9294 void test_visitBinaryExpression_starID() { | |
| 9295 // 1 * 2.0 | |
| 9296 BinaryExpression node = AstFactory.binaryExpression( | |
| 9297 _resolvedInteger(1), | |
| 9298 TokenType.PLUS, | |
| 9299 _resolvedDouble(2.0)); | |
| 9300 node.staticElement = getMethod(_typeProvider.numType, "*"); | |
| 9301 expect(_analyze(node), same(_typeProvider.doubleType)); | |
| 9302 _listener.assertNoErrors(); | |
| 9303 } | |
| 9304 | |
| 9305 void test_visitBinaryExpression_star_notSpecial() { | 9579 void test_visitBinaryExpression_star_notSpecial() { |
| 9306 // class A { | 9580 // class A { |
| 9307 // A operator *(double value); | 9581 // A operator *(double value); |
| 9308 // } | 9582 // } |
| 9309 // (a as A) * 2.0 | 9583 // (a as A) * 2.0 |
| 9310 ClassElementImpl classA = ElementFactory.classElement2("A"); | 9584 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 9311 InterfaceType typeA = classA.type; | 9585 InterfaceType typeA = classA.type; |
| 9312 MethodElement operator = | 9586 MethodElement operator = |
| 9313 ElementFactory.methodElement("*", typeA, [_typeProvider.doubleType]); | 9587 ElementFactory.methodElement("*", typeA, [_typeProvider.doubleType]); |
| 9314 classA.methods = <MethodElement>[operator]; | 9588 classA.methods = <MethodElement>[operator]; |
| 9315 BinaryExpression node = AstFactory.binaryExpression( | 9589 BinaryExpression node = AstFactory.binaryExpression( |
| 9316 AstFactory.asExpression( | 9590 AstFactory.asExpression( |
| 9317 AstFactory.identifier3("a"), | 9591 AstFactory.identifier3("a"), |
| 9318 AstFactory.typeName(classA)), | 9592 AstFactory.typeName(classA)), |
| 9319 TokenType.PLUS, | 9593 TokenType.PLUS, |
| 9320 _resolvedDouble(2.0)); | 9594 _resolvedDouble(2.0)); |
| 9321 node.staticElement = operator; | 9595 node.staticElement = operator; |
| 9322 expect(_analyze(node), same(typeA)); | 9596 expect(_analyze(node), same(typeA)); |
| 9323 _listener.assertNoErrors(); | 9597 _listener.assertNoErrors(); |
| 9324 } | 9598 } |
| 9325 | 9599 |
| 9600 void test_visitBinaryExpression_starID() { |
| 9601 // 1 * 2.0 |
| 9602 BinaryExpression node = AstFactory.binaryExpression( |
| 9603 _resolvedInteger(1), |
| 9604 TokenType.PLUS, |
| 9605 _resolvedDouble(2.0)); |
| 9606 node.staticElement = getMethod(_typeProvider.numType, "*"); |
| 9607 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 9608 _listener.assertNoErrors(); |
| 9609 } |
| 9610 |
| 9326 void test_visitBooleanLiteral_false() { | 9611 void test_visitBooleanLiteral_false() { |
| 9327 // false | 9612 // false |
| 9328 Expression node = AstFactory.booleanLiteral(false); | 9613 Expression node = AstFactory.booleanLiteral(false); |
| 9329 expect(_analyze(node), same(_typeProvider.boolType)); | 9614 expect(_analyze(node), same(_typeProvider.boolType)); |
| 9330 _listener.assertNoErrors(); | 9615 _listener.assertNoErrors(); |
| 9331 } | 9616 } |
| 9332 | 9617 |
| 9333 void test_visitBooleanLiteral_true() { | 9618 void test_visitBooleanLiteral_true() { |
| 9334 // true | 9619 // true |
| 9335 Expression node = AstFactory.booleanLiteral(true); | 9620 Expression node = AstFactory.booleanLiteral(true); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9418 expectedNamedTypes["p"] = dynamicType; | 9703 expectedNamedTypes["p"] = dynamicType; |
| 9419 _assertFunctionType( | 9704 _assertFunctionType( |
| 9420 _typeProvider.intType, | 9705 _typeProvider.intType, |
| 9421 null, | 9706 null, |
| 9422 null, | 9707 null, |
| 9423 expectedNamedTypes, | 9708 expectedNamedTypes, |
| 9424 resultType); | 9709 resultType); |
| 9425 _listener.assertNoErrors(); | 9710 _listener.assertNoErrors(); |
| 9426 } | 9711 } |
| 9427 | 9712 |
| 9713 void test_visitFunctionExpression_normal_block() { |
| 9714 // (p1, p2) {} |
| 9715 DartType dynamicType = _typeProvider.dynamicType; |
| 9716 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); |
| 9717 _setType(p1, dynamicType); |
| 9718 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); |
| 9719 _setType(p2, dynamicType); |
| 9720 FunctionExpression node = _resolvedFunctionExpression( |
| 9721 AstFactory.formalParameterList([p1, p2]), |
| 9722 AstFactory.blockFunctionBody2()); |
| 9723 _analyze5(p1); |
| 9724 _analyze5(p2); |
| 9725 DartType resultType = _analyze(node); |
| 9726 _assertFunctionType( |
| 9727 dynamicType, |
| 9728 <DartType>[dynamicType, dynamicType], |
| 9729 null, |
| 9730 null, |
| 9731 resultType); |
| 9732 _listener.assertNoErrors(); |
| 9733 } |
| 9734 |
| 9735 void test_visitFunctionExpression_normal_expression() { |
| 9736 // (p1, p2) -> 0 |
| 9737 DartType dynamicType = _typeProvider.dynamicType; |
| 9738 FormalParameter p = AstFactory.simpleFormalParameter3("p"); |
| 9739 _setType(p, dynamicType); |
| 9740 FunctionExpression node = _resolvedFunctionExpression( |
| 9741 AstFactory.formalParameterList([p]), |
| 9742 AstFactory.expressionFunctionBody(_resolvedInteger(0))); |
| 9743 _analyze5(p); |
| 9744 DartType resultType = _analyze(node); |
| 9745 _assertFunctionType( |
| 9746 _typeProvider.intType, |
| 9747 <DartType>[dynamicType], |
| 9748 null, |
| 9749 null, |
| 9750 resultType); |
| 9751 _listener.assertNoErrors(); |
| 9752 } |
| 9753 |
| 9428 void test_visitFunctionExpression_normalAndNamed_block() { | 9754 void test_visitFunctionExpression_normalAndNamed_block() { |
| 9429 // (p1, {p2 : 0}) {} | 9755 // (p1, {p2 : 0}) {} |
| 9430 DartType dynamicType = _typeProvider.dynamicType; | 9756 DartType dynamicType = _typeProvider.dynamicType; |
| 9431 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); | 9757 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); |
| 9432 _setType(p1, dynamicType); | 9758 _setType(p1, dynamicType); |
| 9433 FormalParameter p2 = AstFactory.namedFormalParameter( | 9759 FormalParameter p2 = AstFactory.namedFormalParameter( |
| 9434 AstFactory.simpleFormalParameter3("p2"), | 9760 AstFactory.simpleFormalParameter3("p2"), |
| 9435 _resolvedInteger(0)); | 9761 _resolvedInteger(0)); |
| 9436 _setType(p2, dynamicType); | 9762 _setType(p2, dynamicType); |
| 9437 FunctionExpression node = _resolvedFunctionExpression( | 9763 FunctionExpression node = _resolvedFunctionExpression( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9516 DartType resultType = _analyze(node); | 9842 DartType resultType = _analyze(node); |
| 9517 _assertFunctionType( | 9843 _assertFunctionType( |
| 9518 _typeProvider.intType, | 9844 _typeProvider.intType, |
| 9519 <DartType>[dynamicType], | 9845 <DartType>[dynamicType], |
| 9520 <DartType>[dynamicType], | 9846 <DartType>[dynamicType], |
| 9521 null, | 9847 null, |
| 9522 resultType); | 9848 resultType); |
| 9523 _listener.assertNoErrors(); | 9849 _listener.assertNoErrors(); |
| 9524 } | 9850 } |
| 9525 | 9851 |
| 9526 void test_visitFunctionExpression_normal_block() { | |
| 9527 // (p1, p2) {} | |
| 9528 DartType dynamicType = _typeProvider.dynamicType; | |
| 9529 FormalParameter p1 = AstFactory.simpleFormalParameter3("p1"); | |
| 9530 _setType(p1, dynamicType); | |
| 9531 FormalParameter p2 = AstFactory.simpleFormalParameter3("p2"); | |
| 9532 _setType(p2, dynamicType); | |
| 9533 FunctionExpression node = _resolvedFunctionExpression( | |
| 9534 AstFactory.formalParameterList([p1, p2]), | |
| 9535 AstFactory.blockFunctionBody2()); | |
| 9536 _analyze5(p1); | |
| 9537 _analyze5(p2); | |
| 9538 DartType resultType = _analyze(node); | |
| 9539 _assertFunctionType( | |
| 9540 dynamicType, | |
| 9541 <DartType>[dynamicType, dynamicType], | |
| 9542 null, | |
| 9543 null, | |
| 9544 resultType); | |
| 9545 _listener.assertNoErrors(); | |
| 9546 } | |
| 9547 | |
| 9548 void test_visitFunctionExpression_normal_expression() { | |
| 9549 // (p1, p2) -> 0 | |
| 9550 DartType dynamicType = _typeProvider.dynamicType; | |
| 9551 FormalParameter p = AstFactory.simpleFormalParameter3("p"); | |
| 9552 _setType(p, dynamicType); | |
| 9553 FunctionExpression node = _resolvedFunctionExpression( | |
| 9554 AstFactory.formalParameterList([p]), | |
| 9555 AstFactory.expressionFunctionBody(_resolvedInteger(0))); | |
| 9556 _analyze5(p); | |
| 9557 DartType resultType = _analyze(node); | |
| 9558 _assertFunctionType( | |
| 9559 _typeProvider.intType, | |
| 9560 <DartType>[dynamicType], | |
| 9561 null, | |
| 9562 null, | |
| 9563 resultType); | |
| 9564 _listener.assertNoErrors(); | |
| 9565 } | |
| 9566 | |
| 9567 void test_visitFunctionExpression_positional_block() { | 9852 void test_visitFunctionExpression_positional_block() { |
| 9568 // ([p1 = 0, p2 = 0]) {} | 9853 // ([p1 = 0, p2 = 0]) {} |
| 9569 DartType dynamicType = _typeProvider.dynamicType; | 9854 DartType dynamicType = _typeProvider.dynamicType; |
| 9570 FormalParameter p1 = AstFactory.positionalFormalParameter( | 9855 FormalParameter p1 = AstFactory.positionalFormalParameter( |
| 9571 AstFactory.simpleFormalParameter3("p1"), | 9856 AstFactory.simpleFormalParameter3("p1"), |
| 9572 _resolvedInteger(0)); | 9857 _resolvedInteger(0)); |
| 9573 _setType(p1, dynamicType); | 9858 _setType(p1, dynamicType); |
| 9574 FormalParameter p2 = AstFactory.positionalFormalParameter( | 9859 FormalParameter p2 = AstFactory.positionalFormalParameter( |
| 9575 AstFactory.simpleFormalParameter3("p2"), | 9860 AstFactory.simpleFormalParameter3("p2"), |
| 9576 _resolvedInteger(0)); | 9861 _resolvedInteger(0)); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9851 } | 10136 } |
| 9852 | 10137 |
| 9853 void test_visitPostfixExpression_plusPlus() { | 10138 void test_visitPostfixExpression_plusPlus() { |
| 9854 // 0++ | 10139 // 0++ |
| 9855 PostfixExpression node = | 10140 PostfixExpression node = |
| 9856 AstFactory.postfixExpression(_resolvedInteger(0), TokenType.PLUS_PLUS); | 10141 AstFactory.postfixExpression(_resolvedInteger(0), TokenType.PLUS_PLUS); |
| 9857 expect(_analyze(node), same(_typeProvider.intType)); | 10142 expect(_analyze(node), same(_typeProvider.intType)); |
| 9858 _listener.assertNoErrors(); | 10143 _listener.assertNoErrors(); |
| 9859 } | 10144 } |
| 9860 | 10145 |
| 10146 void test_visitPrefixedIdentifier_getter() { |
| 10147 DartType boolType = _typeProvider.boolType; |
| 10148 PropertyAccessorElementImpl getter = |
| 10149 ElementFactory.getterElement("b", false, boolType); |
| 10150 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); |
| 10151 node.identifier.staticElement = getter; |
| 10152 expect(_analyze(node), same(boolType)); |
| 10153 _listener.assertNoErrors(); |
| 10154 } |
| 10155 |
| 10156 void test_visitPrefixedIdentifier_setter() { |
| 10157 DartType boolType = _typeProvider.boolType; |
| 10158 FieldElementImpl field = |
| 10159 ElementFactory.fieldElement("b", false, false, false, boolType); |
| 10160 PropertyAccessorElement setter = field.setter; |
| 10161 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); |
| 10162 node.identifier.staticElement = setter; |
| 10163 expect(_analyze(node), same(boolType)); |
| 10164 _listener.assertNoErrors(); |
| 10165 } |
| 10166 |
| 10167 void test_visitPrefixedIdentifier_variable() { |
| 10168 VariableElementImpl variable = ElementFactory.localVariableElement2("b"); |
| 10169 variable.type = _typeProvider.boolType; |
| 10170 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); |
| 10171 node.identifier.staticElement = variable; |
| 10172 expect(_analyze(node), same(_typeProvider.boolType)); |
| 10173 _listener.assertNoErrors(); |
| 10174 } |
| 10175 |
| 9861 void test_visitPrefixExpression_bang() { | 10176 void test_visitPrefixExpression_bang() { |
| 9862 // !0 | 10177 // !0 |
| 9863 PrefixExpression node = | 10178 PrefixExpression node = |
| 9864 AstFactory.prefixExpression(TokenType.BANG, _resolvedInteger(0)); | 10179 AstFactory.prefixExpression(TokenType.BANG, _resolvedInteger(0)); |
| 9865 expect(_analyze(node), same(_typeProvider.boolType)); | 10180 expect(_analyze(node), same(_typeProvider.boolType)); |
| 9866 _listener.assertNoErrors(); | 10181 _listener.assertNoErrors(); |
| 9867 } | 10182 } |
| 9868 | 10183 |
| 9869 void test_visitPrefixExpression_minus() { | 10184 void test_visitPrefixExpression_minus() { |
| 9870 // -0 | 10185 // -0 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9907 void test_visitPrefixExpression_tilde() { | 10222 void test_visitPrefixExpression_tilde() { |
| 9908 // ~0 | 10223 // ~0 |
| 9909 PrefixExpression node = | 10224 PrefixExpression node = |
| 9910 AstFactory.prefixExpression(TokenType.TILDE, _resolvedInteger(0)); | 10225 AstFactory.prefixExpression(TokenType.TILDE, _resolvedInteger(0)); |
| 9911 MethodElement tildeMethod = getMethod(_typeProvider.intType, "~"); | 10226 MethodElement tildeMethod = getMethod(_typeProvider.intType, "~"); |
| 9912 node.staticElement = tildeMethod; | 10227 node.staticElement = tildeMethod; |
| 9913 expect(_analyze(node), same(_typeProvider.intType)); | 10228 expect(_analyze(node), same(_typeProvider.intType)); |
| 9914 _listener.assertNoErrors(); | 10229 _listener.assertNoErrors(); |
| 9915 } | 10230 } |
| 9916 | 10231 |
| 9917 void test_visitPrefixedIdentifier_getter() { | |
| 9918 DartType boolType = _typeProvider.boolType; | |
| 9919 PropertyAccessorElementImpl getter = | |
| 9920 ElementFactory.getterElement("b", false, boolType); | |
| 9921 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); | |
| 9922 node.identifier.staticElement = getter; | |
| 9923 expect(_analyze(node), same(boolType)); | |
| 9924 _listener.assertNoErrors(); | |
| 9925 } | |
| 9926 | |
| 9927 void test_visitPrefixedIdentifier_setter() { | |
| 9928 DartType boolType = _typeProvider.boolType; | |
| 9929 FieldElementImpl field = | |
| 9930 ElementFactory.fieldElement("b", false, false, false, boolType); | |
| 9931 PropertyAccessorElement setter = field.setter; | |
| 9932 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); | |
| 9933 node.identifier.staticElement = setter; | |
| 9934 expect(_analyze(node), same(boolType)); | |
| 9935 _listener.assertNoErrors(); | |
| 9936 } | |
| 9937 | |
| 9938 void test_visitPrefixedIdentifier_variable() { | |
| 9939 VariableElementImpl variable = ElementFactory.localVariableElement2("b"); | |
| 9940 variable.type = _typeProvider.boolType; | |
| 9941 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); | |
| 9942 node.identifier.staticElement = variable; | |
| 9943 expect(_analyze(node), same(_typeProvider.boolType)); | |
| 9944 _listener.assertNoErrors(); | |
| 9945 } | |
| 9946 | |
| 9947 void test_visitPropertyAccess_propagated_getter() { | 10232 void test_visitPropertyAccess_propagated_getter() { |
| 9948 DartType boolType = _typeProvider.boolType; | 10233 DartType boolType = _typeProvider.boolType; |
| 9949 PropertyAccessorElementImpl getter = | 10234 PropertyAccessorElementImpl getter = |
| 9950 ElementFactory.getterElement("b", false, boolType); | 10235 ElementFactory.getterElement("b", false, boolType); |
| 9951 PropertyAccess node = | 10236 PropertyAccess node = |
| 9952 AstFactory.propertyAccess2(AstFactory.identifier3("a"), "b"); | 10237 AstFactory.propertyAccess2(AstFactory.identifier3("a"), "b"); |
| 9953 node.propertyName.propagatedElement = getter; | 10238 node.propertyName.propagatedElement = getter; |
| 9954 expect(_analyze2(node, false), same(boolType)); | 10239 expect(_analyze2(node, false), same(boolType)); |
| 9955 _listener.assertNoErrors(); | 10240 _listener.assertNoErrors(); |
| 9956 } | 10241 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10035 | 10320 |
| 10036 void test_visitThisExpression() { | 10321 void test_visitThisExpression() { |
| 10037 // this | 10322 // this |
| 10038 InterfaceType thisType = | 10323 InterfaceType thisType = |
| 10039 ElementFactory.classElement("B", ElementFactory.classElement2("A").type)
.type; | 10324 ElementFactory.classElement("B", ElementFactory.classElement2("A").type)
.type; |
| 10040 Expression node = AstFactory.thisExpression(); | 10325 Expression node = AstFactory.thisExpression(); |
| 10041 expect(_analyze3(node, thisType), same(thisType)); | 10326 expect(_analyze3(node, thisType), same(thisType)); |
| 10042 _listener.assertNoErrors(); | 10327 _listener.assertNoErrors(); |
| 10043 } | 10328 } |
| 10044 | 10329 |
| 10330 void test_visitThrowExpression_withoutValue() { |
| 10331 // throw |
| 10332 Expression node = AstFactory.throwExpression(); |
| 10333 expect(_analyze(node), same(_typeProvider.bottomType)); |
| 10334 _listener.assertNoErrors(); |
| 10335 } |
| 10336 |
| 10045 void test_visitThrowExpression_withValue() { | 10337 void test_visitThrowExpression_withValue() { |
| 10046 // throw 0 | 10338 // throw 0 |
| 10047 Expression node = AstFactory.throwExpression2(_resolvedInteger(0)); | 10339 Expression node = AstFactory.throwExpression2(_resolvedInteger(0)); |
| 10048 expect(_analyze(node), same(_typeProvider.bottomType)); | 10340 expect(_analyze(node), same(_typeProvider.bottomType)); |
| 10049 _listener.assertNoErrors(); | 10341 _listener.assertNoErrors(); |
| 10050 } | 10342 } |
| 10051 | |
| 10052 void test_visitThrowExpression_withoutValue() { | |
| 10053 // throw | |
| 10054 Expression node = AstFactory.throwExpression(); | |
| 10055 expect(_analyze(node), same(_typeProvider.bottomType)); | |
| 10056 _listener.assertNoErrors(); | |
| 10057 } | |
| 10058 | 10343 |
| 10059 /** | 10344 /** |
| 10060 * Return the type associated with the given expression after the static type
analyzer has | 10345 * Return the type associated with the given expression after the static type
analyzer has |
| 10061 * computed a type for it. | 10346 * computed a type for it. |
| 10062 * | 10347 * |
| 10063 * @param node the expression with which the type is associated | 10348 * @param node the expression with which the type is associated |
| 10064 * @return the type associated with the expression | 10349 * @return the type associated with the expression |
| 10065 */ | 10350 */ |
| 10066 DartType _analyze(Expression node) => _analyze4(node, null, true); | 10351 DartType _analyze(Expression node) => _analyze4(node, null, true); |
| 10067 | 10352 |
| (...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11463 String code = r''' | 11748 String code = r''' |
| 11464 main() { | 11749 main() { |
| 11465 var v = (() {return 42;})(); | 11750 var v = (() {return 42;})(); |
| 11466 }'''; | 11751 }'''; |
| 11467 _assertPropagatedReturnType( | 11752 _assertPropagatedReturnType( |
| 11468 code, | 11753 code, |
| 11469 typeProvider.dynamicType, | 11754 typeProvider.dynamicType, |
| 11470 typeProvider.intType); | 11755 typeProvider.intType); |
| 11471 } | 11756 } |
| 11472 | 11757 |
| 11473 void test_CanvasElement_getContext() { | |
| 11474 String code = r''' | |
| 11475 import 'dart:html'; | |
| 11476 main(CanvasElement canvas) { | |
| 11477 var context = canvas.getContext('2d'); | |
| 11478 }'''; | |
| 11479 Source source = addSource(code); | |
| 11480 LibraryElement library = resolve(source); | |
| 11481 assertNoErrors(source); | |
| 11482 verify([source]); | |
| 11483 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 11484 SimpleIdentifier identifier = EngineTestCase.findNode( | |
| 11485 unit, | |
| 11486 code, | |
| 11487 "context", | |
| 11488 (node) => node is SimpleIdentifier); | |
| 11489 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); | |
| 11490 } | |
| 11491 | |
| 11492 void test_Future_then() { | |
| 11493 String code = r''' | |
| 11494 import 'dart:async'; | |
| 11495 main(Future<int> firstFuture) { | |
| 11496 firstFuture.then((p1) { | |
| 11497 return 1.0; | |
| 11498 }).then((p2) { | |
| 11499 return new Future<String>.value('str'); | |
| 11500 }).then((p3) { | |
| 11501 }); | |
| 11502 }'''; | |
| 11503 Source source = addSource(code); | |
| 11504 LibraryElement library = resolve(source); | |
| 11505 assertNoErrors(source); | |
| 11506 verify([source]); | |
| 11507 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 11508 // p1 | |
| 11509 FormalParameter p1 = EngineTestCase.findNode( | |
| 11510 unit, | |
| 11511 code, | |
| 11512 "p1) {", | |
| 11513 (node) => node is SimpleFormalParameter); | |
| 11514 expect(p1.identifier.propagatedType, same(typeProvider.intType)); | |
| 11515 // p2 | |
| 11516 FormalParameter p2 = EngineTestCase.findNode( | |
| 11517 unit, | |
| 11518 code, | |
| 11519 "p2) {", | |
| 11520 (node) => node is SimpleFormalParameter); | |
| 11521 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); | |
| 11522 // p3 | |
| 11523 FormalParameter p3 = EngineTestCase.findNode( | |
| 11524 unit, | |
| 11525 code, | |
| 11526 "p3) {", | |
| 11527 (node) => node is SimpleFormalParameter); | |
| 11528 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); | |
| 11529 } | |
| 11530 | |
| 11531 void test_as() { | 11758 void test_as() { |
| 11532 Source source = addSource(r''' | 11759 Source source = addSource(r''' |
| 11533 class A { | 11760 class A { |
| 11534 bool get g => true; | 11761 bool get g => true; |
| 11535 } | 11762 } |
| 11536 A f(var p) { | 11763 A f(var p) { |
| 11537 if ((p as A).g) { | 11764 if ((p as A).g) { |
| 11538 return p; | 11765 return p; |
| 11539 } else { | 11766 } else { |
| 11540 return null; | 11767 return null; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11652 SimpleIdentifier identifier = EngineTestCase.findNode( | 11879 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 11653 unit, | 11880 unit, |
| 11654 code, | 11881 code, |
| 11655 "v; // return", | 11882 "v; // return", |
| 11656 (node) => node is SimpleIdentifier); | 11883 (node) => node is SimpleIdentifier); |
| 11657 expect(identifier.staticType, same(typeProvider.intType)); | 11884 expect(identifier.staticType, same(typeProvider.intType)); |
| 11658 expect(identifier.propagatedType, same(null)); | 11885 expect(identifier.propagatedType, same(null)); |
| 11659 } | 11886 } |
| 11660 } | 11887 } |
| 11661 | 11888 |
| 11889 void test_CanvasElement_getContext() { |
| 11890 String code = r''' |
| 11891 import 'dart:html'; |
| 11892 main(CanvasElement canvas) { |
| 11893 var context = canvas.getContext('2d'); |
| 11894 }'''; |
| 11895 Source source = addSource(code); |
| 11896 LibraryElement library = resolve(source); |
| 11897 assertNoErrors(source); |
| 11898 verify([source]); |
| 11899 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 11900 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 11901 unit, |
| 11902 code, |
| 11903 "context", |
| 11904 (node) => node is SimpleIdentifier); |
| 11905 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); |
| 11906 } |
| 11907 |
| 11662 void test_finalPropertyInducingVariable_classMember_instance() { | 11908 void test_finalPropertyInducingVariable_classMember_instance() { |
| 11663 addNamedSource("/lib.dart", r''' | 11909 addNamedSource("/lib.dart", r''' |
| 11664 class A { | 11910 class A { |
| 11665 final v = 0; | 11911 final v = 0; |
| 11666 }'''); | 11912 }'''); |
| 11667 String code = r''' | 11913 String code = r''' |
| 11668 import 'lib.dart'; | 11914 import 'lib.dart'; |
| 11669 f(A a) { | 11915 f(A a) { |
| 11670 return a.v; // marker | 11916 return a.v; // marker |
| 11671 }'''; | 11917 }'''; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11963 code, | 12209 code, |
| 11964 "v)", | 12210 "v)", |
| 11965 (node) => node is SimpleFormalParameter); | 12211 (node) => node is SimpleFormalParameter); |
| 11966 expect(vParameter.identifier.propagatedType, same(stringType)); | 12212 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 11967 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); | 12213 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); |
| 11968 SimpleIdentifier vIdentifier = | 12214 SimpleIdentifier vIdentifier = |
| 11969 EngineTestCase.findNode(unit, code, "v;", (node) => node is SimpleIdenti
fier); | 12215 EngineTestCase.findNode(unit, code, "v;", (node) => node is SimpleIdenti
fier); |
| 11970 expect(vIdentifier.propagatedType, same(stringType)); | 12216 expect(vIdentifier.propagatedType, same(stringType)); |
| 11971 } | 12217 } |
| 11972 | 12218 |
| 12219 void test_Future_then() { |
| 12220 String code = r''' |
| 12221 import 'dart:async'; |
| 12222 main(Future<int> firstFuture) { |
| 12223 firstFuture.then((p1) { |
| 12224 return 1.0; |
| 12225 }).then((p2) { |
| 12226 return new Future<String>.value('str'); |
| 12227 }).then((p3) { |
| 12228 }); |
| 12229 }'''; |
| 12230 Source source = addSource(code); |
| 12231 LibraryElement library = resolve(source); |
| 12232 assertNoErrors(source); |
| 12233 verify([source]); |
| 12234 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12235 // p1 |
| 12236 FormalParameter p1 = EngineTestCase.findNode( |
| 12237 unit, |
| 12238 code, |
| 12239 "p1) {", |
| 12240 (node) => node is SimpleFormalParameter); |
| 12241 expect(p1.identifier.propagatedType, same(typeProvider.intType)); |
| 12242 // p2 |
| 12243 FormalParameter p2 = EngineTestCase.findNode( |
| 12244 unit, |
| 12245 code, |
| 12246 "p2) {", |
| 12247 (node) => node is SimpleFormalParameter); |
| 12248 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); |
| 12249 // p3 |
| 12250 FormalParameter p3 = EngineTestCase.findNode( |
| 12251 unit, |
| 12252 code, |
| 12253 "p3) {", |
| 12254 (node) => node is SimpleFormalParameter); |
| 12255 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); |
| 12256 } |
| 12257 |
| 11973 void test_initializer() { | 12258 void test_initializer() { |
| 11974 Source source = addSource(r''' | 12259 Source source = addSource(r''' |
| 11975 f() { | 12260 f() { |
| 11976 var v = 0; | 12261 var v = 0; |
| 11977 return v; | 12262 return v; |
| 11978 }'''); | 12263 }'''); |
| 11979 LibraryElement library = resolve(source); | 12264 LibraryElement library = resolve(source); |
| 11980 assertNoErrors(source); | 12265 assertNoErrors(source); |
| 11981 verify([source]); | 12266 verify([source]); |
| 11982 CompilationUnit unit = resolveCompilationUnit(source, library); | 12267 CompilationUnit unit = resolveCompilationUnit(source, library); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12045 SimpleIdentifier identifier = EngineTestCase.findNode( | 12330 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 12046 unit, | 12331 unit, |
| 12047 code, | 12332 code, |
| 12048 "v; // marker", | 12333 "v; // marker", |
| 12049 (node) => node is SimpleIdentifier); | 12334 (node) => node is SimpleIdentifier); |
| 12050 expect(identifier.staticType, same(typeProvider.intType)); | 12335 expect(identifier.staticType, same(typeProvider.intType)); |
| 12051 expect(identifier.propagatedType, same(null)); | 12336 expect(identifier.propagatedType, same(null)); |
| 12052 } | 12337 } |
| 12053 } | 12338 } |
| 12054 | 12339 |
| 12055 void test_isNot_conditional() { | 12340 void test_is_conditional() { |
| 12056 Source source = addSource(r''' | 12341 Source source = addSource(r''' |
| 12057 class A {} | 12342 class A {} |
| 12058 A f(var p) { | 12343 A f(var p) { |
| 12059 return (p is! A) ? null : p; | 12344 return (p is A) ? p : null; |
| 12060 }'''); | 12345 }'''); |
| 12061 LibraryElement library = resolve(source); | 12346 LibraryElement library = resolve(source); |
| 12062 assertNoErrors(source); | 12347 assertNoErrors(source); |
| 12063 verify([source]); | 12348 verify([source]); |
| 12064 CompilationUnit unit = resolveCompilationUnit(source, library); | 12349 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12065 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12350 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12066 InterfaceType typeA = classA.element.type; | 12351 InterfaceType typeA = classA.element.type; |
| 12067 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12352 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12068 BlockFunctionBody body = | 12353 BlockFunctionBody body = |
| 12069 function.functionExpression.body as BlockFunctionBody; | 12354 function.functionExpression.body as BlockFunctionBody; |
| 12070 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 12355 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 12071 ConditionalExpression conditional = | 12356 ConditionalExpression conditional = |
| 12072 statement.expression as ConditionalExpression; | 12357 statement.expression as ConditionalExpression; |
| 12073 SimpleIdentifier variableName = | 12358 SimpleIdentifier variableName = |
| 12074 conditional.elseExpression as SimpleIdentifier; | 12359 conditional.thenExpression as SimpleIdentifier; |
| 12075 expect(variableName.propagatedType, same(typeA)); | 12360 expect(variableName.propagatedType, same(typeA)); |
| 12076 } | 12361 } |
| 12077 | 12362 |
| 12078 void test_isNot_if() { | 12363 void test_is_if() { |
| 12079 Source source = addSource(r''' | 12364 Source source = addSource(r''' |
| 12080 class A {} | 12365 class A {} |
| 12081 A f(var p) { | 12366 A f(var p) { |
| 12082 if (p is! A) { | 12367 if (p is A) { |
| 12368 return p; |
| 12369 } else { |
| 12083 return null; | 12370 return null; |
| 12084 } else { | |
| 12085 return p; | |
| 12086 } | 12371 } |
| 12087 }'''); | 12372 }'''); |
| 12088 LibraryElement library = resolve(source); | 12373 LibraryElement library = resolve(source); |
| 12089 assertNoErrors(source); | 12374 assertNoErrors(source); |
| 12090 verify([source]); | 12375 verify([source]); |
| 12091 CompilationUnit unit = resolveCompilationUnit(source, library); | 12376 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12092 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12377 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12093 InterfaceType typeA = classA.element.type; | 12378 InterfaceType typeA = classA.element.type; |
| 12094 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12379 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12095 BlockFunctionBody body = | 12380 BlockFunctionBody body = |
| 12096 function.functionExpression.body as BlockFunctionBody; | 12381 function.functionExpression.body as BlockFunctionBody; |
| 12097 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12382 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12098 ReturnStatement statement = | 12383 ReturnStatement statement = |
| 12099 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; | 12384 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 12100 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12385 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12101 expect(variableName.propagatedType, same(typeA)); | 12386 expect(variableName.propagatedType, same(typeA)); |
| 12102 } | 12387 } |
| 12103 | 12388 |
| 12104 void test_isNot_if_logicalOr() { | 12389 void test_is_if_lessSpecific() { |
| 12105 Source source = addSource(r''' | 12390 Source source = addSource(r''' |
| 12106 class A {} | 12391 class A {} |
| 12107 A f(var p) { | 12392 A f(A p) { |
| 12108 if (p is! A || null == p) { | 12393 if (p is String) { |
| 12394 return p; |
| 12395 } else { |
| 12109 return null; | 12396 return null; |
| 12110 } else { | |
| 12111 return p; | |
| 12112 } | 12397 } |
| 12113 }'''); | 12398 }'''); |
| 12114 LibraryElement library = resolve(source); | 12399 LibraryElement library = resolve(source); |
| 12115 assertNoErrors(source); | 12400 assertNoErrors(source); |
| 12401 verify([source]); |
| 12116 CompilationUnit unit = resolveCompilationUnit(source, library); | 12402 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12117 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12403 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0)
; |
| 12118 InterfaceType typeA = classA.element.type; | 12404 // InterfaceType typeA = classA.getElement().getType(); |
| 12119 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12405 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12120 BlockFunctionBody body = | 12406 BlockFunctionBody body = |
| 12121 function.functionExpression.body as BlockFunctionBody; | 12407 function.functionExpression.body as BlockFunctionBody; |
| 12122 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12408 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12123 ReturnStatement statement = | 12409 ReturnStatement statement = |
| 12124 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; | 12410 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 12125 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12411 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12126 expect(variableName.propagatedType, same(typeA)); | 12412 expect(variableName.propagatedType, same(null)); |
| 12127 } | 12413 } |
| 12128 | 12414 |
| 12129 void test_isNot_postConditional() { | 12415 void test_is_if_logicalAnd() { |
| 12130 Source source = addSource(r''' | 12416 Source source = addSource(r''' |
| 12131 class A {} | 12417 class A {} |
| 12132 A f(var p) { | 12418 A f(var p) { |
| 12133 A a = (p is! A) ? throw null : p; | 12419 if (p is A && p != null) { |
| 12134 return p; | 12420 return p; |
| 12421 } else { |
| 12422 return null; |
| 12423 } |
| 12135 }'''); | 12424 }'''); |
| 12136 LibraryElement library = resolve(source); | 12425 LibraryElement library = resolve(source); |
| 12137 assertNoErrors(source); | 12426 assertNoErrors(source); |
| 12138 verify([source]); | 12427 verify([source]); |
| 12139 CompilationUnit unit = resolveCompilationUnit(source, library); | 12428 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12140 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12429 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12141 InterfaceType typeA = classA.element.type; | 12430 InterfaceType typeA = classA.element.type; |
| 12142 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12431 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12143 BlockFunctionBody body = | 12432 BlockFunctionBody body = |
| 12144 function.functionExpression.body as BlockFunctionBody; | 12433 function.functionExpression.body as BlockFunctionBody; |
| 12145 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12434 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12435 ReturnStatement statement = |
| 12436 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 12146 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12437 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12147 expect(variableName.propagatedType, same(typeA)); | 12438 expect(variableName.propagatedType, same(typeA)); |
| 12148 } | 12439 } |
| 12149 | 12440 |
| 12150 void test_isNot_postIf() { | 12441 void test_is_postConditional() { |
| 12151 Source source = addSource(r''' | 12442 Source source = addSource(r''' |
| 12152 class A {} | 12443 class A {} |
| 12153 A f(var p) { | 12444 A f(var p) { |
| 12154 if (p is! A) { | 12445 A a = (p is A) ? p : throw null; |
| 12155 return null; | |
| 12156 } | |
| 12157 return p; | 12446 return p; |
| 12158 }'''); | 12447 }'''); |
| 12159 LibraryElement library = resolve(source); | 12448 LibraryElement library = resolve(source); |
| 12160 assertNoErrors(source); | 12449 assertNoErrors(source); |
| 12161 verify([source]); | 12450 verify([source]); |
| 12162 CompilationUnit unit = resolveCompilationUnit(source, library); | 12451 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12163 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12452 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12164 InterfaceType typeA = classA.element.type; | 12453 InterfaceType typeA = classA.element.type; |
| 12165 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12454 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12166 BlockFunctionBody body = | 12455 BlockFunctionBody body = |
| 12167 function.functionExpression.body as BlockFunctionBody; | 12456 function.functionExpression.body as BlockFunctionBody; |
| 12168 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12457 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12169 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12458 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12170 expect(variableName.propagatedType, same(typeA)); | 12459 expect(variableName.propagatedType, same(typeA)); |
| 12171 } | 12460 } |
| 12172 | 12461 |
| 12173 void test_is_conditional() { | 12462 void test_is_postIf() { |
| 12174 Source source = addSource(r''' | 12463 Source source = addSource(r''' |
| 12175 class A {} | 12464 class A {} |
| 12176 A f(var p) { | 12465 A f(var p) { |
| 12177 return (p is A) ? p : null; | 12466 if (p is A) { |
| 12467 A a = p; |
| 12468 } else { |
| 12469 return null; |
| 12470 } |
| 12471 return p; |
| 12178 }'''); | 12472 }'''); |
| 12179 LibraryElement library = resolve(source); | 12473 LibraryElement library = resolve(source); |
| 12180 assertNoErrors(source); | 12474 assertNoErrors(source); |
| 12181 verify([source]); | 12475 verify([source]); |
| 12182 CompilationUnit unit = resolveCompilationUnit(source, library); | 12476 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12183 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12477 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12184 InterfaceType typeA = classA.element.type; | 12478 InterfaceType typeA = classA.element.type; |
| 12185 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12479 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12186 BlockFunctionBody body = | 12480 BlockFunctionBody body = |
| 12187 function.functionExpression.body as BlockFunctionBody; | 12481 function.functionExpression.body as BlockFunctionBody; |
| 12188 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 12482 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12189 ConditionalExpression conditional = | 12483 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12190 statement.expression as ConditionalExpression; | |
| 12191 SimpleIdentifier variableName = | |
| 12192 conditional.thenExpression as SimpleIdentifier; | |
| 12193 expect(variableName.propagatedType, same(typeA)); | 12484 expect(variableName.propagatedType, same(typeA)); |
| 12194 } | 12485 } |
| 12195 | 12486 |
| 12196 void test_is_if() { | 12487 void test_is_subclass() { |
| 12488 Source source = addSource(r''' |
| 12489 class A {} |
| 12490 class B extends A { |
| 12491 B m() => this; |
| 12492 } |
| 12493 A f(A p) { |
| 12494 if (p is B) { |
| 12495 return p.m(); |
| 12496 } |
| 12497 return p; |
| 12498 }'''); |
| 12499 LibraryElement library = resolve(source); |
| 12500 assertNoErrors(source); |
| 12501 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12502 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; |
| 12503 BlockFunctionBody body = |
| 12504 function.functionExpression.body as BlockFunctionBody; |
| 12505 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12506 ReturnStatement statement = |
| 12507 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 12508 MethodInvocation invocation = statement.expression as MethodInvocation; |
| 12509 expect(invocation.methodName.propagatedElement, isNotNull); |
| 12510 } |
| 12511 |
| 12512 void test_is_while() { |
| 12197 Source source = addSource(r''' | 12513 Source source = addSource(r''' |
| 12198 class A {} | 12514 class A {} |
| 12199 A f(var p) { | 12515 A f(var p) { |
| 12200 if (p is A) { | 12516 while (p is A) { |
| 12201 return p; | 12517 return p; |
| 12202 } else { | |
| 12203 return null; | |
| 12204 } | 12518 } |
| 12519 return p; |
| 12205 }'''); | 12520 }'''); |
| 12206 LibraryElement library = resolve(source); | 12521 LibraryElement library = resolve(source); |
| 12207 assertNoErrors(source); | 12522 assertNoErrors(source); |
| 12208 verify([source]); | 12523 verify([source]); |
| 12209 CompilationUnit unit = resolveCompilationUnit(source, library); | 12524 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12210 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12525 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12211 InterfaceType typeA = classA.element.type; | 12526 InterfaceType typeA = classA.element.type; |
| 12212 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12527 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12213 BlockFunctionBody body = | 12528 BlockFunctionBody body = |
| 12214 function.functionExpression.body as BlockFunctionBody; | 12529 function.functionExpression.body as BlockFunctionBody; |
| 12215 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12530 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; |
| 12216 ReturnStatement statement = | 12531 ReturnStatement statement = |
| 12217 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 12532 (whileStatement.body as Block).statements[0] as ReturnStatement; |
| 12218 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12533 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12219 expect(variableName.propagatedType, same(typeA)); | 12534 expect(variableName.propagatedType, same(typeA)); |
| 12220 } | 12535 } |
| 12221 | 12536 |
| 12222 void test_is_if_lessSpecific() { | 12537 void test_isNot_conditional() { |
| 12223 Source source = addSource(r''' | 12538 Source source = addSource(r''' |
| 12224 class A {} | 12539 class A {} |
| 12225 A f(A p) { | 12540 A f(var p) { |
| 12226 if (p is String) { | 12541 return (p is! A) ? null : p; |
| 12227 return p; | |
| 12228 } else { | |
| 12229 return null; | |
| 12230 } | |
| 12231 }'''); | 12542 }'''); |
| 12232 LibraryElement library = resolve(source); | 12543 LibraryElement library = resolve(source); |
| 12233 assertNoErrors(source); | 12544 assertNoErrors(source); |
| 12234 verify([source]); | |
| 12235 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 12236 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0)
; | |
| 12237 // InterfaceType typeA = classA.getElement().getType(); | |
| 12238 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | |
| 12239 BlockFunctionBody body = | |
| 12240 function.functionExpression.body as BlockFunctionBody; | |
| 12241 IfStatement ifStatement = body.block.statements[0] as IfStatement; | |
| 12242 ReturnStatement statement = | |
| 12243 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | |
| 12244 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | |
| 12245 expect(variableName.propagatedType, same(null)); | |
| 12246 } | |
| 12247 | |
| 12248 void test_is_if_logicalAnd() { | |
| 12249 Source source = addSource(r''' | |
| 12250 class A {} | |
| 12251 A f(var p) { | |
| 12252 if (p is A && p != null) { | |
| 12253 return p; | |
| 12254 } else { | |
| 12255 return null; | |
| 12256 } | |
| 12257 }'''); | |
| 12258 LibraryElement library = resolve(source); | |
| 12259 assertNoErrors(source); | |
| 12260 verify([source]); | 12545 verify([source]); |
| 12261 CompilationUnit unit = resolveCompilationUnit(source, library); | 12546 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12262 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12547 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12263 InterfaceType typeA = classA.element.type; | 12548 InterfaceType typeA = classA.element.type; |
| 12264 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12549 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12265 BlockFunctionBody body = | 12550 BlockFunctionBody body = |
| 12266 function.functionExpression.body as BlockFunctionBody; | 12551 function.functionExpression.body as BlockFunctionBody; |
| 12267 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12552 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 12268 ReturnStatement statement = | 12553 ConditionalExpression conditional = |
| 12269 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 12554 statement.expression as ConditionalExpression; |
| 12270 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12555 SimpleIdentifier variableName = |
| 12556 conditional.elseExpression as SimpleIdentifier; |
| 12271 expect(variableName.propagatedType, same(typeA)); | 12557 expect(variableName.propagatedType, same(typeA)); |
| 12272 } | 12558 } |
| 12273 | 12559 |
| 12274 void test_is_postConditional() { | 12560 void test_isNot_if() { |
| 12275 Source source = addSource(r''' | 12561 Source source = addSource(r''' |
| 12276 class A {} | 12562 class A {} |
| 12277 A f(var p) { | 12563 A f(var p) { |
| 12278 A a = (p is A) ? p : throw null; | 12564 if (p is! A) { |
| 12279 return p; | 12565 return null; |
| 12566 } else { |
| 12567 return p; |
| 12568 } |
| 12280 }'''); | 12569 }'''); |
| 12281 LibraryElement library = resolve(source); | 12570 LibraryElement library = resolve(source); |
| 12282 assertNoErrors(source); | 12571 assertNoErrors(source); |
| 12283 verify([source]); | 12572 verify([source]); |
| 12284 CompilationUnit unit = resolveCompilationUnit(source, library); | 12573 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12285 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12574 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12286 InterfaceType typeA = classA.element.type; | 12575 InterfaceType typeA = classA.element.type; |
| 12287 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12576 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12288 BlockFunctionBody body = | 12577 BlockFunctionBody body = |
| 12289 function.functionExpression.body as BlockFunctionBody; | 12578 function.functionExpression.body as BlockFunctionBody; |
| 12290 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12579 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12580 ReturnStatement statement = |
| 12581 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; |
| 12291 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12582 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12292 expect(variableName.propagatedType, same(typeA)); | 12583 expect(variableName.propagatedType, same(typeA)); |
| 12293 } | 12584 } |
| 12294 | 12585 |
| 12295 void test_is_postIf() { | 12586 void test_isNot_if_logicalOr() { |
| 12296 Source source = addSource(r''' | 12587 Source source = addSource(r''' |
| 12297 class A {} | 12588 class A {} |
| 12298 A f(var p) { | 12589 A f(var p) { |
| 12299 if (p is A) { | 12590 if (p is! A || null == p) { |
| 12300 A a = p; | 12591 return null; |
| 12301 } else { | 12592 } else { |
| 12302 return null; | 12593 return p; |
| 12303 } | 12594 } |
| 12595 }'''); |
| 12596 LibraryElement library = resolve(source); |
| 12597 assertNoErrors(source); |
| 12598 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12599 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12600 InterfaceType typeA = classA.element.type; |
| 12601 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12602 BlockFunctionBody body = |
| 12603 function.functionExpression.body as BlockFunctionBody; |
| 12604 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12605 ReturnStatement statement = |
| 12606 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; |
| 12607 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12608 expect(variableName.propagatedType, same(typeA)); |
| 12609 } |
| 12610 |
| 12611 void test_isNot_postConditional() { |
| 12612 Source source = addSource(r''' |
| 12613 class A {} |
| 12614 A f(var p) { |
| 12615 A a = (p is! A) ? throw null : p; |
| 12304 return p; | 12616 return p; |
| 12305 }'''); | 12617 }'''); |
| 12306 LibraryElement library = resolve(source); | 12618 LibraryElement library = resolve(source); |
| 12307 assertNoErrors(source); | 12619 assertNoErrors(source); |
| 12308 verify([source]); | 12620 verify([source]); |
| 12309 CompilationUnit unit = resolveCompilationUnit(source, library); | 12621 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12310 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12622 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12311 InterfaceType typeA = classA.element.type; | 12623 InterfaceType typeA = classA.element.type; |
| 12312 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12624 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12313 BlockFunctionBody body = | 12625 BlockFunctionBody body = |
| 12314 function.functionExpression.body as BlockFunctionBody; | 12626 function.functionExpression.body as BlockFunctionBody; |
| 12315 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12627 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12316 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12628 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12317 expect(variableName.propagatedType, same(typeA)); | 12629 expect(variableName.propagatedType, same(typeA)); |
| 12318 } | 12630 } |
| 12319 | 12631 |
| 12320 void test_is_subclass() { | 12632 void test_isNot_postIf() { |
| 12321 Source source = addSource(r''' | 12633 Source source = addSource(r''' |
| 12322 class A {} | 12634 class A {} |
| 12323 class B extends A { | 12635 A f(var p) { |
| 12324 B m() => this; | 12636 if (p is! A) { |
| 12325 } | 12637 return null; |
| 12326 A f(A p) { | |
| 12327 if (p is B) { | |
| 12328 return p.m(); | |
| 12329 } | 12638 } |
| 12330 return p; | 12639 return p; |
| 12331 }'''); | 12640 }'''); |
| 12332 LibraryElement library = resolve(source); | |
| 12333 assertNoErrors(source); | |
| 12334 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 12335 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; | |
| 12336 BlockFunctionBody body = | |
| 12337 function.functionExpression.body as BlockFunctionBody; | |
| 12338 IfStatement ifStatement = body.block.statements[0] as IfStatement; | |
| 12339 ReturnStatement statement = | |
| 12340 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | |
| 12341 MethodInvocation invocation = statement.expression as MethodInvocation; | |
| 12342 expect(invocation.methodName.propagatedElement, isNotNull); | |
| 12343 } | |
| 12344 | |
| 12345 void test_is_while() { | |
| 12346 Source source = addSource(r''' | |
| 12347 class A {} | |
| 12348 A f(var p) { | |
| 12349 while (p is A) { | |
| 12350 return p; | |
| 12351 } | |
| 12352 return p; | |
| 12353 }'''); | |
| 12354 LibraryElement library = resolve(source); | 12641 LibraryElement library = resolve(source); |
| 12355 assertNoErrors(source); | 12642 assertNoErrors(source); |
| 12356 verify([source]); | 12643 verify([source]); |
| 12357 CompilationUnit unit = resolveCompilationUnit(source, library); | 12644 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12358 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12645 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12359 InterfaceType typeA = classA.element.type; | 12646 InterfaceType typeA = classA.element.type; |
| 12360 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12647 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12361 BlockFunctionBody body = | 12648 BlockFunctionBody body = |
| 12362 function.functionExpression.body as BlockFunctionBody; | 12649 function.functionExpression.body as BlockFunctionBody; |
| 12363 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; | 12650 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12364 ReturnStatement statement = | |
| 12365 (whileStatement.body as Block).statements[0] as ReturnStatement; | |
| 12366 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12651 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12367 expect(variableName.propagatedType, same(typeA)); | 12652 expect(variableName.propagatedType, same(typeA)); |
| 12368 } | 12653 } |
| 12369 | 12654 |
| 12370 void test_issue20904BuggyTypePromotionAtIfJoin_2() { | 12655 void test_issue20904BuggyTypePromotionAtIfJoin_2() { |
| 12371 // https://code.google.com/p/dart/issues/detail?id=20904 | 12656 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 12372 enableUnionTypes(false); | 12657 enableUnionTypes(false); |
| 12373 String code = r''' | 12658 String code = r''' |
| 12374 f(var message) { | 12659 f(var message) { |
| 12375 if (message is Function) { | 12660 if (message is Function) { |
| (...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13475 // check propagated type | 13760 // check propagated type |
| 13476 FunctionType propagatedType = node.propagatedType as FunctionType; | 13761 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13477 expect(propagatedType.returnType, test.typeProvider.stringType); | 13762 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13478 } on AnalysisException catch (e, stackTrace) { | 13763 } on AnalysisException catch (e, stackTrace) { |
| 13479 thrownException[0] = new CaughtException(e, stackTrace); | 13764 thrownException[0] = new CaughtException(e, stackTrace); |
| 13480 } | 13765 } |
| 13481 } | 13766 } |
| 13482 return null; | 13767 return null; |
| 13483 } | 13768 } |
| 13484 } | 13769 } |
| OLD | NEW |