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

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

Issue 11049038: Change compile-time errors into dynamic errors in instance creation expression (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 2 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
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/dart_api_impl_test.cc » ('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) 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/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 // parsed type arguments. 739 // parsed type arguments.
740 AbstractTypeArguments& arguments = 740 AbstractTypeArguments& arguments =
741 AbstractTypeArguments::Handle(parameterized_type.arguments()); 741 AbstractTypeArguments::Handle(parameterized_type.arguments());
742 if (!arguments.IsNull()) { 742 if (!arguments.IsNull()) {
743 intptr_t num_arguments = arguments.Length(); 743 intptr_t num_arguments = arguments.Length();
744 AbstractType& type_argument = AbstractType::Handle(); 744 AbstractType& type_argument = AbstractType::Handle();
745 for (intptr_t i = 0; i < num_arguments; i++) { 745 for (intptr_t i = 0; i < num_arguments; i++) {
746 type_argument = arguments.TypeAt(i); 746 type_argument = arguments.TypeAt(i);
747 type_argument = FinalizeType(cls, type_argument, finalization); 747 type_argument = FinalizeType(cls, type_argument, finalization);
748 if (type_argument.IsMalformed()) { 748 if (type_argument.IsMalformed()) {
749 // Malformed type arguments to a constructor of a generic type are
750 // reported as a compile-time error.
751 if (finalization >= kCanonicalizeForCreation) {
752 const Script& script = Script::Handle(cls.script());
753 const String& type_name =
754 String::Handle(parameterized_type.UserVisibleName());
755 ReportError(script, parameterized_type.token_pos(),
756 "type '%s' has malformed type argument",
757 type_name.ToCString());
758 }
749 // In production mode, malformed type arguments are mapped to Dynamic. 759 // In production mode, malformed type arguments are mapped to Dynamic.
750 // In checked mode, a type with malformed type arguments is malformed. 760 // In checked mode, a type with malformed type arguments is malformed.
751 if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) { 761 if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) {
752 const Error& error = Error::Handle(type_argument.malformed_error()); 762 const Error& error = Error::Handle(type_argument.malformed_error());
753 const String& type_name = 763 const String& type_name =
754 String::Handle(parameterized_type.UserVisibleName()); 764 String::Handle(parameterized_type.UserVisibleName());
755 FinalizeMalformedType(error, cls, parameterized_type, finalization, 765 FinalizeMalformedType(error, cls, parameterized_type, finalization,
756 "type '%s' has malformed type argument", 766 "type '%s' has malformed type argument",
757 type_name.ToCString()); 767 type_name.ToCString());
758 return parameterized_type.raw(); 768 return parameterized_type.raw();
759 } else { 769 } else {
760 type_argument = Type::DynamicType(); 770 type_argument = Type::DynamicType();
761 } 771 }
762 } 772 }
763 arguments.SetTypeAt(i, type_argument); 773 arguments.SetTypeAt(i, type_argument);
764 } 774 }
765 } 775 }
766 776
767 // The finalized type argument vector needs num_type_arguments types. 777 // The finalized type argument vector needs num_type_arguments types.
768 const intptr_t num_type_arguments = type_class.NumTypeArguments(); 778 const intptr_t num_type_arguments = type_class.NumTypeArguments();
769 // The type class has num_type_parameters type parameters. 779 // The type class has num_type_parameters type parameters.
770 const intptr_t num_type_parameters = type_class.NumTypeParameters(); 780 const intptr_t num_type_parameters = type_class.NumTypeParameters();
771 781
772 // Initialize the type argument vector. 782 // Initialize the type argument vector.
773 // Check the number of parsed type arguments, if any. 783 // Check the number of parsed type arguments, if any.
774 // Specifying no type arguments indicates a raw type, which is not an error. 784 // Specifying no type arguments indicates a raw type, which is not an error.
775 // However, type parameter bounds are checked below, even for a raw type. 785 // However, type parameter bounds are checked below, even for a raw type.
776 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { 786 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) {
777 // Wrong number of type arguments. The type is malformed. 787 // Wrong number of type arguments. The type is malformed.
788 if (finalization >= kCanonicalizeForCreation) {
789 const Script& script = Script::Handle(cls.script());
790 const String& type_name =
791 String::Handle(parameterized_type.UserVisibleName());
792 ReportError(script, parameterized_type.token_pos(),
793 "wrong number of type arguments in type '%s'",
794 type_name.ToCString());
795 }
778 FinalizeMalformedType( 796 FinalizeMalformedType(
779 Error::Handle(), // No previous error. 797 Error::Handle(), // No previous error.
780 cls, parameterized_type, finalization, 798 cls, parameterized_type, finalization,
781 "wrong number of type arguments in type '%s'", 799 "wrong number of type arguments in type '%s'",
782 String::Handle(parameterized_type.UserVisibleName()).ToCString()); 800 String::Handle(parameterized_type.UserVisibleName()).ToCString());
783 return parameterized_type.raw(); 801 return parameterized_type.raw();
784 } 802 }
785 // The full type argument vector consists of the type arguments of the 803 // The full type argument vector consists of the type arguments of the
786 // super types of type_class, which may be initialized from the parsed 804 // super types of type_class, which may be initialized from the parsed
787 // type arguments, followed by the parsed type arguments. 805 // type arguments, followed by the parsed type arguments.
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 void ClassFinalizer::ReportError(const char* format, ...) { 1589 void ClassFinalizer::ReportError(const char* format, ...) {
1572 va_list args; 1590 va_list args;
1573 va_start(args, format); 1591 va_start(args, format);
1574 const Error& error = Error::Handle( 1592 const Error& error = Error::Handle(
1575 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); 1593 Parser::FormatError(Script::Handle(), -1, "Error", format, args));
1576 va_end(args); 1594 va_end(args);
1577 ReportError(error); 1595 ReportError(error);
1578 } 1596 }
1579 1597
1580 } // namespace dart 1598 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698