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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/warnings.dart

Issue 152593002: Version 1.2.0-dev.3.1 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 part of dart2js; 5 part of dart2js;
6 6
7 const DONT_KNOW_HOW_TO_FIX = ""; 7 const DONT_KNOW_HOW_TO_FIX = "";
8 8
9 /** 9 /**
10 * The messages in this file should meet the following guide lines: 10 * The messages in this file should meet the following guide lines:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 * An INFO message should always be preceded by a non-INFO message, and the 61 * An INFO message should always be preceded by a non-INFO message, and the
62 * INFO messages are additional details about the preceding non-INFO 62 * INFO messages are additional details about the preceding non-INFO
63 * message. For example, consider duplicated elements. First report a WARNING 63 * message. For example, consider duplicated elements. First report a WARNING
64 * or ERROR about the duplicated element, and then report an INFO about the 64 * or ERROR about the duplicated element, and then report an INFO about the
65 * location of the existing element. 65 * location of the existing element.
66 * 66 *
67 * Generally, we want to provide messages that consists of three sentences: 67 * Generally, we want to provide messages that consists of three sentences:
68 * 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we 68 * 1. what is wrong, 2. why is it wrong, 3. how do I fix it. However, we
69 * combine the first two in [template] and the last in [howToFix]. 69 * combine the first two in [template] and the last in [howToFix].
70 */ 70 */
71 // TODO(johnnniwinther): For Infos, consider adding a reference to the
72 // error/warning/hint that they belong to.
71 class MessageKind { 73 class MessageKind {
72 /// Should describe what is wrong and why. 74 /// Should describe what is wrong and why.
73 final String template; 75 final String template;
74 76
75 /// Should describe how to fix the problem. Elided when using --terse option. 77 /// Should describe how to fix the problem. Elided when using --terse option.
76 final String howToFix; 78 final String howToFix;
77 79
78 /** 80 /**
79 * Examples will be checked by 81 * Examples will be checked by
80 * tests/compiler/dart2js/message_kind_test.dart. 82 * tests/compiler/dart2js/message_kind_test.dart.
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 "Error: A setter must have exactly one argument."); 863 "Error: A setter must have exactly one argument.");
862 864
863 static const MessageKind NO_STATIC_OVERRIDE = const MessageKind( 865 static const MessageKind NO_STATIC_OVERRIDE = const MessageKind(
864 "Error: Static member cannot override instance member '#{memberName}' of " 866 "Error: Static member cannot override instance member '#{memberName}' of "
865 "'#{className}'."); 867 "'#{className}'.");
866 868
867 static const MessageKind NO_STATIC_OVERRIDE_CONT = const MessageKind( 869 static const MessageKind NO_STATIC_OVERRIDE_CONT = const MessageKind(
868 "Info: This is the instance member that cannot be overridden " 870 "Info: This is the instance member that cannot be overridden "
869 "by a static member."); 871 "by a static member.");
870 872
873 static const MessageKind INSTANCE_STATIC_SAME_NAME = const MessageKind(
874 "Warning: Instance member '#{memberName}' and static member of "
875 "superclass '#{className}' have the same name.");
876
877 static const MessageKind INSTANCE_STATIC_SAME_NAME_CONT = const MessageKind(
878 "Info: This is the static member with the same name.");
879
880 static const MessageKind INVALID_OVERRIDE_METHOD = const MessageKind(
881 "Warning: The type '#{declaredType}' of method '#{name}' declared in "
882 "'#{class}' is not a subtype of the overridden method type "
883 "'#{inheritedType}' inherited from '#{inheritedClass}'.");
884
885 static const MessageKind INVALID_OVERRIDDEN_METHOD = const MessageKind(
886 "Info: This is the overridden method '#{name}' declared in class "
887 "'#{class}'.");
888
889 static const MessageKind INVALID_OVERRIDE_GETTER = const MessageKind(
890 "Warning: The type '#{declaredType}' of getter '#{name}' declared in "
891 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
892 "overridden getter inherited from '#{inheritedClass}'.");
893
894 static const MessageKind INVALID_OVERRIDDEN_GETTER = const MessageKind(
895 "Info: This is the overridden getter '#{name}' declared in class "
896 "'#{class}'.");
897
898 static const MessageKind INVALID_OVERRIDE_GETTER_WITH_FIELD =
899 const MessageKind(
900 "Warning: The type '#{declaredType}' of field '#{name}' declared in "
901 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
902 "overridden getter inherited from '#{inheritedClass}'.");
903
904 static const MessageKind INVALID_OVERRIDE_FIELD_WITH_GETTER =
905 const MessageKind(
906 "Warning: The type '#{declaredType}' of getter '#{name}' declared in "
907 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
908 "overridden field inherited from '#{inheritedClass}'.");
909
910 static const MessageKind INVALID_OVERRIDE_SETTER = const MessageKind(
911 "Warning: The type '#{declaredType}' of setter '#{name}' declared in "
912 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
913 "overridden setter inherited from '#{inheritedClass}'.");
914
915 static const MessageKind INVALID_OVERRIDDEN_SETTER = const MessageKind(
916 "Info: This is the overridden setter '#{name}' declared in class "
917 "'#{class}'.");
918
919 static const MessageKind INVALID_OVERRIDE_SETTER_WITH_FIELD =
920 const MessageKind(
921 "Warning: The type '#{declaredType}' of field '#{name}' declared in "
922 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
923 "overridden setter inherited from '#{inheritedClass}'.");
924
925 static const MessageKind INVALID_OVERRIDE_FIELD_WITH_SETTER =
926 const MessageKind(
927 "Warning: The type '#{declaredType}' of setter '#{name}' declared in "
928 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
929 "overridden field inherited from '#{inheritedClass}'.");
930
931 static const MessageKind INVALID_OVERRIDE_FIELD = const MessageKind(
932 "Warning: The type '#{declaredType}' of field '#{name}' declared in "
933 "'#{class}' is not assignable to the type '#{inheritedType}' of the "
934 "overridden field inherited from '#{inheritedClass}'.");
935
936 static const MessageKind INVALID_OVERRIDDEN_FIELD = const MessageKind(
937 "Info: This is the overridden field '#{name}' declared in class "
938 "'#{class}'.");
939
871 static const MessageKind CANNOT_OVERRIDE_FIELD_WITH_METHOD = 940 static const MessageKind CANNOT_OVERRIDE_FIELD_WITH_METHOD =
872 const MessageKind( 941 const MessageKind(
873 "Error: Method cannot override field '#{memberName}' of " 942 "Error: Method '#{name}' in '#{class}' can't override field from "
874 "'#{className}'."); 943 "'#{inheritedClass}'.");
875 944
876 static const MessageKind CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT = 945 static const MessageKind CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT =
877 const MessageKind( 946 const MessageKind(
878 "Info: This is the field that cannot be overridden by a method."); 947 "Info: This is the field that cannot be overridden by a method.");
879 948
880 static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_FIELD = 949 static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_FIELD =
881 const MessageKind( 950 const MessageKind(
882 "Error: Field cannot override method '#{memberName}' of " 951 "Error: Field '#{name}' in '#{class}' can't override method from "
883 "'#{className}'."); 952 "'#{inheritedClass}'.");
884 953
885 static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT = 954 static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT =
886 const MessageKind( 955 const MessageKind(
887 "Info: This is the method that cannot be overridden by a field."); 956 "Info: This is the method that cannot be overridden by a field.");
888 957
889 static const MessageKind BAD_ARITY_OVERRIDE = const MessageKind( 958 static const MessageKind CANNOT_OVERRIDE_GETTER_WITH_METHOD =
890 "Error: Cannot override method '#{memberName}' in '#{className}'; " 959 const MessageKind(
891 "the parameters do not match."); 960 "Error: Method '#{name}' in '#{class}' can't override getter from "
961 "'#{inheritedClass}'.");
892 962
893 static const MessageKind BAD_ARITY_OVERRIDE_CONT = const MessageKind( 963 static const MessageKind CANNOT_OVERRIDE_GETTER_WITH_METHOD_CONT =
894 "Info: This is the method whose parameters do not match."); 964 const MessageKind(
965 "Info: This is the getter that cannot be overridden by a method.");
966
967 static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_GETTER =
968 const MessageKind(
969 "Error: Getter '#{name}' in '#{class}' can't override method from "
970 "'#{inheritedClass}'.");
971
972 static const MessageKind CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT =
973 const MessageKind(
974 "Info: This is the method that cannot be overridden by a getter.");
895 975
896 static const MessageKind MISSING_FORMALS = const MessageKind( 976 static const MessageKind MISSING_FORMALS = const MessageKind(
897 "Error: Formal parameters are missing."); 977 "Error: Formal parameters are missing.");
898 978
899 static const MessageKind EXTRA_FORMALS = const MessageKind( 979 static const MessageKind EXTRA_FORMALS = const MessageKind(
900 "Error: Formal parameters are not allowed here."); 980 "Error: Formal parameters are not allowed here.");
901 981
902 static const MessageKind UNARY_OPERATOR_BAD_ARITY = const MessageKind( 982 static const MessageKind UNARY_OPERATOR_BAD_ARITY = const MessageKind(
903 "Error: Operator '#{operatorName}' must have no parameters."); 983 "Error: Operator '#{operatorName}' must have no parameters.");
904 984
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1400 const MessageKind( 1480 const MessageKind(
1401 "Error: '#{keyword}' is a reserved word and can't be used here.", 1481 "Error: '#{keyword}' is a reserved word and can't be used here.",
1402 howToFix: "Try using a different name.", 1482 howToFix: "Try using a different name.",
1403 examples: const ["do() {} main() {}"]); 1483 examples: const ["do() {} main() {}"]);
1404 1484
1405 static const MessageKind UNUSED_METHOD = const MessageKind( 1485 static const MessageKind UNUSED_METHOD = const MessageKind(
1406 "Hint: The method '#{method_name}' is never called.", 1486 "Hint: The method '#{method_name}' is never called.",
1407 howToFix: "Consider deleting it.", 1487 howToFix: "Consider deleting it.",
1408 examples: const ["deadCode() {} main() {}"]); 1488 examples: const ["deadCode() {} main() {}"]);
1409 1489
1490 static const MessageKind ABSTRACT_METHOD = const MessageKind(
1491 "Warning: The method '#{name}' has no implementation in "
1492 "class '#{class}'.",
1493 howToFix: "Try adding a body to '#{name}' or declaring "
1494 "'#{class}' to be 'abstract'.",
1495 examples: const ["""
1496 class Class {
1497 method();
1498 }
1499 main() => new Class();
1500 """]);
1501
1502 static const MessageKind ABSTRACT_GETTER = const MessageKind(
1503 "Warning: The getter '#{name}' has no implementation in "
1504 "class '#{class}'.",
1505 howToFix: "Try adding a body to '#{name}' or declaring "
1506 "'#{class}' to be 'abstract'.",
1507 examples: const ["""
1508 class Class {
1509 get getter;
1510 }
1511 main() => new Class();
1512 """]);
1513
1514 static const MessageKind ABSTRACT_SETTER = const MessageKind(
1515 "Warning: The setter '#{name}' has no implementation in "
1516 "class '#{class}'.",
1517 howToFix: "Try adding a body to '#{name}' or declaring "
1518 "'#{class}' to be 'abstract'.",
1519 examples: const ["""
1520 class Class {
1521 set setter(_);
1522 }
1523 main() => new Class();
1524 """]);
1525
1526 static const MessageKind INHERIT_GETTER_AND_METHOD = const MessageKind(
1527 "Warning: The class '#{class}' can't inherit both getters and methods "
1528 "by the named '#{name}'.",
1529 howToFix: DONT_KNOW_HOW_TO_FIX,
1530 examples: const ["""
1531 class A {
1532 get member => null;
1533 }
1534 class B {
1535 member() {}
1536 }
1537 class Class implements A, B {
1538 }
1539 main() => new Class();
1540 """]);
1541
1542 static const MessageKind INHERITED_METHOD = const MessageKind(
1543 "Info: The inherited method '#{name}' is declared here in class "
1544 "'#{class}'.");
1545
1546 static const MessageKind INHERITED_EXPLICIT_GETTER = const MessageKind(
1547 "Info: The inherited getter '#{name}' is declared here in class "
1548 "'#{class}'.");
1549
1550 static const MessageKind INHERITED_IMPLICIT_GETTER = const MessageKind(
1551 "Info: The inherited getter '#{name}' is implicitly declared by this "
1552 "field in class '#{class}'.");
1553
1554 static const MessageKind UNIMPLEMENTED_METHOD_ONE = const MessageKind(
1555 "Warning: '#{class}' doesn't implement '#{method}' "
1556 "declared in '#{declarer}'.",
1557 howToFix: "Try adding an implementation of '#{name}' or declaring "
1558 "'#{class}' to be 'abstract'.",
1559 examples: const ["""
1560 abstract class I {
1561 m();
1562 }
1563 class C implements I {}
1564 main() => new C();
1565 """, """
1566 abstract class I {
1567 m();
1568 }
1569 class C extends I {}
1570 main() => new C();
1571 """]);
1572
1410 static const MessageKind UNIMPLEMENTED_METHOD = const MessageKind( 1573 static const MessageKind UNIMPLEMENTED_METHOD = const MessageKind(
1411 "Warning: '#{class_name}' doesn't implement '#{member_name}'.", 1574 "Warning: '#{class}' doesn't implement '#{method}'.",
1412 howToFix: "Try adding an implementation of '#{member_name}'.", 1575 howToFix: "Try adding an implementation of '#{name}' or declaring "
1576 "'#{class}' to be 'abstract'.",
1413 examples: const [""" 1577 examples: const ["""
1414 abstract class I { 1578 abstract class I {
1415 m(); 1579 m();
1416 } 1580 }
1417 1581
1418 class C implements I {} 1582 abstract class J {
1419 1583 m();
1420 class D implements I {
1421 m() {}
1422 } 1584 }
1423 1585
1586 class C implements I, J {}
1587
1424 main() { 1588 main() {
1425 new D().m();
1426 new C(); 1589 new C();
1427 } 1590 }
1428 """, """ 1591 """, """
1429 abstract class I { 1592 abstract class I {
1430 m(); 1593 m();
1431 } 1594 }
1432 1595
1433 class C extends I {} 1596 abstract class J {
1434 1597 m();
1435 class D extends I {
1436 m() {}
1437 } 1598 }
1438 1599
1600 class C extends I implements J {}
1601
1439 main() { 1602 main() {
1440 new D().m();
1441 new C(); 1603 new C();
1442 } 1604 }
1443 """]); 1605 """]);
1444 1606
1607 static const MessageKind UNIMPLEMENTED_METHOD_CONT = const MessageKind(
1608 "Info: The method '#{name}' is declared here in class '#{class}'.");
1609
1610 static const MessageKind UNIMPLEMENTED_SETTER_ONE = const MessageKind(
1611 "Warning: '#{class}' doesn't implement the setter '#{name}' "
1612 "declared in '#{declarer}'.",
1613 howToFix: "Try adding an implementation of '#{name}' or declaring "
1614 "'#{class}' to be 'abstract'.",
1615 examples: const ["""
1616 abstract class I {
1617 set m(_);
1618 }
1619 class C implements I {}
1620 class D implements I {
1621 set m(_) {}
1622 }
1623 main() {
1624 new D().m = 0;
1625 new C();
1626 }
1627 """]);
1628
1629 static const MessageKind UNIMPLEMENTED_SETTER = const MessageKind(
1630 "Warning: '#{class}' doesn't implement the setter '#{name}'.",
1631 howToFix: "Try adding an implementation of '#{name}' or declaring "
1632 "'#{class}' to be 'abstract'.",
1633 examples: const ["""
1634 abstract class I {
1635 set m(_);
1636 }
1637 abstract class J {
1638 set m(_);
1639 }
1640 class C implements I, J {}
1641 main() => new C();
1642 """, """
1643 abstract class I {
1644 set m(_);
1645 }
1646 abstract class J {
1647 set m(_);
1648 }
1649 class C extends I implements J {}
1650 main() => new C();
1651 """]);
1652
1653 static const MessageKind UNIMPLEMENTED_EXPLICIT_SETTER = const MessageKind(
1654 "Info: The setter '#{name}' is declared here in class '#{class}'.");
1655
1656 static const MessageKind UNIMPLEMENTED_IMPLICIT_SETTER = const MessageKind(
1657 "Info: The setter '#{name}' is implicitly declared by this field "
1658 "in class '#{class}'.");
1659
1660 static const MessageKind UNIMPLEMENTED_GETTER_ONE = const MessageKind(
1661 "Warning: '#{class}' doesn't implement the getter '#{name}' "
1662 "declared in '#{declarer}'.",
1663 howToFix: "Try adding an implementation of '#{name}' or declaring "
1664 "'#{class}' to be 'abstract'.",
1665 examples: const ["""
1666 abstract class I {
1667 get m;
1668 }
1669 class C implements I {}
1670 main() => new C();
1671 """, """
1672 abstract class I {
1673 get m;
1674 }
1675 class C extends I {}
1676 main() => new C();
1677 """]);
1678
1679 static const MessageKind UNIMPLEMENTED_GETTER = const MessageKind(
1680 "Warning: '#{class}' doesn't implement the getter '#{name}'.",
1681 howToFix: "Try adding an implementation of '#{name}' or declaring "
1682 "'#{class}' to be 'abstract'.",
1683 examples: const ["""
1684 abstract class I {
1685 get m;
1686 }
1687 abstract class J {
1688 get m;
1689 }
1690 class C implements I, J {}
1691 main() => new C();
1692 """, """
1693 abstract class I {
1694 get m;
1695 }
1696 abstract class J {
1697 get m;
1698 }
1699 class C extends I implements J {}
1700 main() => new C();
1701 """]);
1702
1703 static const MessageKind UNIMPLEMENTED_EXPLICIT_GETTER = const MessageKind(
1704 "Info: The getter '#{name}' is declared here in class '#{class}'.");
1705
1706 static const MessageKind UNIMPLEMENTED_IMPLICIT_GETTER = const MessageKind(
1707 "Info: The getter '#{name}' is implicitly declared by this field "
1708 "in class '#{class}'.");
1709
1445 static const MessageKind EQUAL_MAP_ENTRY_KEY = const MessageKind( 1710 static const MessageKind EQUAL_MAP_ENTRY_KEY = const MessageKind(
1446 "Warning: An entry with the same key already exists in the map.", 1711 "Warning: An entry with the same key already exists in the map.",
1447 howToFix: "Try removing the previous entry or changing the key in one " 1712 howToFix: "Try removing the previous entry or changing the key in one "
1448 "of the entries.", 1713 "of the entries.",
1449 examples: const [""" 1714 examples: const ["""
1450 main() { 1715 main() {
1451 var m = const {'foo': 1, 'foo': 2}; 1716 var m = const {'foo': 1, 'foo': 2};
1452 }"""]); 1717 }"""]);
1453 1718
1454 static const MessageKind COMPILER_CRASHED = const MessageKind( 1719 static const MessageKind COMPILER_CRASHED = const MessageKind(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1909 }
1645 1910
1646 String computeMessage() { 1911 String computeMessage() {
1647 if (message == null) { 1912 if (message == null) {
1648 message = kind.template; 1913 message = kind.template;
1649 arguments.forEach((key, value) { 1914 arguments.forEach((key, value) {
1650 message = message.replaceAll('#{${key}}', value.toString()); 1915 message = message.replaceAll('#{${key}}', value.toString());
1651 }); 1916 });
1652 assert(invariant( 1917 assert(invariant(
1653 CURRENT_ELEMENT_SPANNABLE, 1918 CURRENT_ELEMENT_SPANNABLE,
1654 !message.contains(new RegExp(r'#\{.+\}')), 1919 kind == MessageKind.GENERIC ||
1920 !message.contains(new RegExp(r'#\{.+\}')),
1655 message: 'Missing arguments in error message: "$message"')); 1921 message: 'Missing arguments in error message: "$message"'));
1656 if (!terse && kind.hasHowToFix) { 1922 if (!terse && kind.hasHowToFix) {
1657 String howToFix = kind.howToFix; 1923 String howToFix = kind.howToFix;
1658 arguments.forEach((key, value) { 1924 arguments.forEach((key, value) {
1659 howToFix = howToFix.replaceAll('#{${key}}', value.toString()); 1925 howToFix = howToFix.replaceAll('#{${key}}', value.toString());
1660 }); 1926 });
1661 message = '$message\n$howToFix'; 1927 message = '$message\n$howToFix';
1662 } 1928 }
1663 } 1929 }
1664 return message; 1930 return message;
(...skipping 30 matching lines...) Expand all
1695 1961
1696 class CompileTimeConstantError extends Diagnostic { 1962 class CompileTimeConstantError extends Diagnostic {
1697 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse) 1963 CompileTimeConstantError(MessageKind kind, Map arguments, bool terse)
1698 : super(kind, arguments, terse); 1964 : super(kind, arguments, terse);
1699 } 1965 }
1700 1966
1701 class CompilationError extends Diagnostic { 1967 class CompilationError extends Diagnostic {
1702 CompilationError(MessageKind kind, Map arguments, bool terse) 1968 CompilationError(MessageKind kind, Map arguments, bool terse)
1703 : super(kind, arguments, terse); 1969 : super(kind, arguments, terse);
1704 } 1970 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/resolution/members.dart ('k') | sdk/lib/_internal/lib/isolate_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698