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

Side by Side Diff: runtime/vm/parser.cc

Issue 2673423003: Improve error message when super constructor is invalid (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 2648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2659 const intptr_t kLen = class_name.Length() + 1; 2659 const intptr_t kLen = class_name.Length() + 1;
2660 ctor_name = Symbols::New(T, ctor_name, kLen, ctor_name.Length() - kLen); 2660 ctor_name = Symbols::New(T, ctor_name, kLen, ctor_name.Length() - kLen);
2661 super_ctor_name = Symbols::FromConcat(T, super_ctor_name, ctor_name); 2661 super_ctor_name = Symbols::FromConcat(T, super_ctor_name, ctor_name);
2662 } 2662 }
2663 } 2663 }
2664 2664
2665 // Resolve super constructor function and check arguments. 2665 // Resolve super constructor function and check arguments.
2666 const Function& super_ctor = 2666 const Function& super_ctor =
2667 Function::ZoneHandle(Z, super_class.LookupConstructor(super_ctor_name)); 2667 Function::ZoneHandle(Z, super_class.LookupConstructor(super_ctor_name));
2668 if (super_ctor.IsNull()) { 2668 if (super_ctor.IsNull()) {
2669 if (super_class.LookupFactory(super_ctor_name) != Function::null()) {
2670 ReportError(supercall_pos,
2671 "illegal implicit call to factory '%s()' in super class",
2672 String::Handle(Z, super_class.Name()).ToCString());
2673 }
2669 ReportError(supercall_pos, 2674 ReportError(supercall_pos,
2670 "unresolved implicit call to super constructor '%s()'", 2675 "unresolved implicit call to super constructor '%s()'",
2671 String::Handle(Z, super_class.Name()).ToCString()); 2676 String::Handle(Z, super_class.Name()).ToCString());
2672 } 2677 }
2673 if (current_function().is_const() && !super_ctor.is_const()) { 2678 if (current_function().is_const() && !super_ctor.is_const()) {
2674 ReportError(supercall_pos, "implicit call to non-const super constructor"); 2679 ReportError(supercall_pos, "implicit call to non-const super constructor");
2675 } 2680 }
2676 2681
2677 String& error_message = String::Handle(Z); 2682 String& error_message = String::Handle(Z);
2678 if (!super_ctor.AreValidArguments(arguments->length(), arguments->names(), 2683 if (!super_ctor.AreValidArguments(arguments->length(), arguments->names(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2710 2715
2711 // 'this' parameter must not be accessible to the other super call arguments. 2716 // 'this' parameter must not be accessible to the other super call arguments.
2712 receiver->set_invisible(true); 2717 receiver->set_invisible(true);
2713 ParseActualParameters(arguments, kAllowConst); 2718 ParseActualParameters(arguments, kAllowConst);
2714 receiver->set_invisible(false); 2719 receiver->set_invisible(false);
2715 2720
2716 // Resolve the constructor. 2721 // Resolve the constructor.
2717 const Function& super_ctor = 2722 const Function& super_ctor =
2718 Function::ZoneHandle(Z, super_class.LookupConstructor(ctor_name)); 2723 Function::ZoneHandle(Z, super_class.LookupConstructor(ctor_name));
2719 if (super_ctor.IsNull()) { 2724 if (super_ctor.IsNull()) {
2725 if (super_class.LookupFactory(ctor_name) != Function::null()) {
2726 ReportError(supercall_pos,
2727 "super class constructor '%s' "
2728 "must not be a factory constructor",
2729 ctor_name.ToCString());
2730 }
2720 ReportError(supercall_pos, "super class constructor '%s' not found", 2731 ReportError(supercall_pos, "super class constructor '%s' not found",
2721 ctor_name.ToCString()); 2732 ctor_name.ToCString());
2722 } 2733 }
2723 if (current_function().is_const() && !super_ctor.is_const()) { 2734 if (current_function().is_const() && !super_ctor.is_const()) {
2724 ReportError(supercall_pos, "super constructor must be const"); 2735 ReportError(supercall_pos, "super constructor must be const");
2725 } 2736 }
2726 String& error_message = String::Handle(Z); 2737 String& error_message = String::Handle(Z);
2727 if (!super_ctor.AreValidArguments(arguments->length(), arguments->names(), 2738 if (!super_ctor.AreValidArguments(arguments->length(), arguments->names(),
2728 &error_message)) { 2739 &error_message)) {
2729 ReportError(supercall_pos, 2740 ReportError(supercall_pos,
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
3095 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver); 3106 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver);
3096 arguments->Add(implicit_argument); 3107 arguments->Add(implicit_argument);
3097 3108
3098 receiver->set_invisible(true); 3109 receiver->set_invisible(true);
3099 ParseActualParameters(arguments, kAllowConst); 3110 ParseActualParameters(arguments, kAllowConst);
3100 receiver->set_invisible(false); 3111 receiver->set_invisible(false);
3101 // Resolve the constructor. 3112 // Resolve the constructor.
3102 const Function& redirect_ctor = 3113 const Function& redirect_ctor =
3103 Function::ZoneHandle(Z, cls.LookupConstructor(ctor_name)); 3114 Function::ZoneHandle(Z, cls.LookupConstructor(ctor_name));
3104 if (redirect_ctor.IsNull()) { 3115 if (redirect_ctor.IsNull()) {
3116 if (cls.LookupFactory(ctor_name) != Function::null()) {
3117 ReportError(
3118 call_pos, "redirection constructor '%s' must not be a factory",
3119 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString());
3120 }
3105 ReportError(call_pos, "constructor '%s' not found", 3121 ReportError(call_pos, "constructor '%s' not found",
3106 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString()); 3122 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString());
3107 } 3123 }
3108 if (current_function().is_const() && !redirect_ctor.is_const()) { 3124 if (current_function().is_const() && !redirect_ctor.is_const()) {
3109 ReportError(call_pos, "redirection constructor '%s' must be const", 3125 ReportError(call_pos, "redirection constructor '%s' must be const",
3110 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString()); 3126 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString());
3111 } 3127 }
3112 String& error_message = String::Handle(Z); 3128 String& error_message = String::Handle(Z);
3113 if (!redirect_ctor.AreValidArguments(arguments->length(), arguments->names(), 3129 if (!redirect_ctor.AreValidArguments(arguments->length(), arguments->names(),
3114 &error_message)) { 3130 &error_message)) {
(...skipping 11836 matching lines...) Expand 10 before | Expand all | Expand 10 after
14951 const ArgumentListNode& function_args, 14967 const ArgumentListNode& function_args,
14952 const LocalVariable* temp_for_last_arg, 14968 const LocalVariable* temp_for_last_arg,
14953 bool is_super_invocation) { 14969 bool is_super_invocation) {
14954 UNREACHABLE(); 14970 UNREACHABLE();
14955 return NULL; 14971 return NULL;
14956 } 14972 }
14957 14973
14958 } // namespace dart 14974 } // namespace dart
14959 14975
14960 #endif // DART_PRECOMPILED_RUNTIME 14976 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698