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

Side by Side Diff: pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Issue 2777533002: Report compile-time error on invalid constructors. (Closed)
Patch Set: Update status files. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_target.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.body_builder; 5 library fasta.body_builder;
6 6
7 import '../parser/parser.dart' show FormalParameterType, optional; 7 import '../parser/parser.dart' show FormalParameterType, optional;
8 8
9 import '../parser/error_kind.dart' show ErrorKind; 9 import '../parser/error_kind.dart' show ErrorKind;
10 10
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 } 1738 }
1739 1739
1740 @override 1740 @override
1741 void endNewExpression(Token token) { 1741 void endNewExpression(Token token) {
1742 debugEvent("NewExpression"); 1742 debugEvent("NewExpression");
1743 Token nameToken = token.next; 1743 Token nameToken = token.next;
1744 Arguments arguments = pop(); 1744 Arguments arguments = pop();
1745 String name = pop(); 1745 String name = pop();
1746 List<DartType> typeArguments = pop(); 1746 List<DartType> typeArguments = pop();
1747 var type = pop(); 1747 var type = pop();
1748 constantExpressionRequired = pop(); 1748 bool savedConstantExpressionRequired = pop();
1749 () {
1750 if (arguments == null) {
1751 push(buildCompileTimeError("No arguments.", nameToken.charOffset));
1752 return;
1753 }
1749 1754
1750 if (arguments == null) { 1755 if (typeArguments != null) {
1751 push(buildCompileTimeError("No arguments.", nameToken.charOffset)); 1756 assert(arguments.types.isEmpty);
1752 return; 1757 arguments.types.addAll(typeArguments);
1753 } 1758 }
1754 1759
1755 if (typeArguments != null) { 1760 String errorName;
1756 assert(arguments.types.isEmpty); 1761 if (type is ClassBuilder) {
1757 arguments.types.addAll(typeArguments); 1762 Builder b = type.findConstructorOrFactory(name);
1758 } 1763 Member target;
1759 1764 if (b == null) {
1760 String errorName; 1765 // Not found. Reported below.
1761 if (type is ClassBuilder) { 1766 } else if (b.isConstructor) {
1762 Builder b = type.findConstructorOrFactory(name); 1767 if (type.isAbstract) {
1763 Member target; 1768 // TODO(ahe): Generate abstract instantiation error.
1764 if (b == null) { 1769 } else {
1765 // Not found. Reported below. 1770 target = b.target;
1766 } else if (b.isConstructor) { 1771 }
1767 if (type.isAbstract) { 1772 } else if (b.isFactory) {
1768 // TODO(ahe): Generate abstract instantiation error. 1773 target = getRedirectionTarget(b.target);
1774 if (target == null) {
1775 push(buildCompileTimeError(
1776 "Cyclic definition of factory '${name}'.",
1777 nameToken.charOffset));
1778 return;
1779 }
1780 }
1781 if (target is Constructor ||
1782 (target is Procedure && target.kind == ProcedureKind.Factory)) {
1783 push(buildStaticInvocation(target, arguments,
1784 isConst: optional("const", token),
1785 charOffset: nameToken.charOffset));
1786 return;
1769 } else { 1787 } else {
1770 target = b.target; 1788 errorName = debugName(type.name, name);
1771 } 1789 }
1772 } else if (b.isFactory) { 1790 } else {
1773 target = getRedirectionTarget(b.target); 1791 errorName = debugName(getNodeName(type), name);
1774 if (target == null) {
1775 push(buildCompileTimeError(
1776 "Cyclic definition of factory '${name}'.", nameToken.charOffset));
1777 return;
1778 }
1779 } 1792 }
1780 if (target is Constructor || 1793 errorName ??= name;
1781 (target is Procedure && target.kind == ProcedureKind.Factory)) { 1794 push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset));
1782 push(buildStaticInvocation(target, arguments, 1795 }();
1783 isConst: optional("const", token), 1796 constantExpressionRequired = savedConstantExpressionRequired;
1784 charOffset: nameToken.charOffset));
1785 return;
1786 } else {
1787 errorName = debugName(type.name, name);
1788 }
1789 } else {
1790 errorName = debugName(getNodeName(type), name);
1791 }
1792 errorName ??= name;
1793 push(throwNoSuchMethodError(errorName, arguments, nameToken.charOffset));
1794 } 1797 }
1795 1798
1796 @override 1799 @override
1797 void endConstExpression(Token token) { 1800 void endConstExpression(Token token) {
1798 debugEvent("endConstExpression"); 1801 debugEvent("endConstExpression");
1799 endNewExpression(token); 1802 endNewExpression(token);
1800 } 1803 }
1801 1804
1802 @override 1805 @override
1803 void endTypeArguments(int count, Token beginToken, Token endToken) { 1806 void endTypeArguments(int count, Token beginToken, Token endToken) {
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 } else if (node is PrefixBuilder) { 2849 } else if (node is PrefixBuilder) {
2847 return node.name; 2850 return node.name;
2848 } else if (node is ThisAccessor) { 2851 } else if (node is ThisAccessor) {
2849 return node.isSuper ? "super" : "this"; 2852 return node.isSuper ? "super" : "this";
2850 } else if (node is BuilderAccessor) { 2853 } else if (node is BuilderAccessor) {
2851 return node.plainNameForRead; 2854 return node.plainNameForRead;
2852 } else { 2855 } else {
2853 return internalError("Unhandled: ${node.runtimeType}"); 2856 return internalError("Unhandled: ${node.runtimeType}");
2854 } 2857 }
2855 } 2858 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/kernel/kernel_target.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698