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

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

Issue 9665013: Generate a dynamic type error when creating an instance with a bound error. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/parser.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/object.h" 5 #include "vm/object.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 2733 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 } 2744 }
2745 type_class = type.type_class(); 2745 type_class = type.type_class();
2746 if (!type_class.IsDynamicClass()) { 2746 if (!type_class.IsDynamicClass()) {
2747 return false; 2747 return false;
2748 } 2748 }
2749 } 2749 }
2750 return true; 2750 return true;
2751 } 2751 }
2752 2752
2753 2753
2754 static RawError* FormatError(const Script& script, 2754 static RawError* FormatError(const Error& prev_error,
2755 const Script& script,
2755 intptr_t token_index, 2756 intptr_t token_index,
2756 const char* format, ...) { 2757 const char* format, ...) {
2757 va_list args; 2758 va_list args;
2758 va_start(args, format); 2759 va_start(args, format);
2759 return Parser::FormatError(script, token_index, "Error", format, args); 2760 if (prev_error.IsNull()) {
2761 return Parser::FormatError(script, token_index, "Error", format, args);
2762 } else {
2763 return Parser::FormatErrorWithAppend(prev_error, script, token_index,
2764 "Error", format, args);
2765 }
2760 } 2766 }
2761 2767
2762 2768
2763 bool AbstractTypeArguments::IsWithinBoundsOf( 2769 bool AbstractTypeArguments::IsWithinBoundsOf(
2764 const Class& cls, 2770 const Class& cls,
2765 const AbstractTypeArguments& bounds_instantiator, 2771 const AbstractTypeArguments& bounds_instantiator,
2766 Error* malformed_error) const { 2772 Error* malformed_error) const {
2767 ASSERT(FLAG_enable_type_checks); 2773 ASSERT(FLAG_enable_type_checks);
2768 ASSERT(IsInstantiated()); 2774 ASSERT(IsInstantiated());
2769 ASSERT(Length() >= cls.NumTypeArguments()); 2775 ASSERT(Length() >= cls.NumTypeArguments());
2770 const intptr_t num_type_params = cls.NumTypeParameters(); 2776 const intptr_t num_type_params = cls.NumTypeParameters();
2771 const intptr_t offset = cls.NumTypeArguments() - num_type_params; 2777 const intptr_t offset = cls.NumTypeArguments() - num_type_params;
2772 AbstractType& type = AbstractType::Handle(); 2778 AbstractType& type = AbstractType::Handle();
2773 AbstractType& bound = AbstractType::Handle(); 2779 AbstractType& bound = AbstractType::Handle();
2774 const TypeArguments& bounds = 2780 const TypeArguments& bounds =
2775 TypeArguments::Handle(cls.type_parameter_bounds()); 2781 TypeArguments::Handle(cls.type_parameter_bounds());
2776 ASSERT((bounds.IsNull() && (num_type_params == 0)) || 2782 ASSERT((bounds.IsNull() && (num_type_params == 0)) ||
2777 (bounds.Length() == num_type_params)); 2783 (bounds.Length() == num_type_params));
2778 for (intptr_t i = 0; i < num_type_params; i++) { 2784 for (intptr_t i = 0; i < num_type_params; i++) {
2779 bound = bounds.TypeAt(i); 2785 bound = bounds.TypeAt(i);
2780 if (!bound.IsDynamicType()) { 2786 if (!bound.IsDynamicType()) {
2781 type = TypeAt(offset + i); 2787 type = TypeAt(offset + i);
2782 if (!bound.IsInstantiated()) { 2788 Error& malformed_bound_error = Error::Handle();
2789 if (bound.IsMalformed()) {
2790 malformed_bound_error = bound.malformed_error();
2791 } else if (!bound.IsInstantiated()) {
2783 bound = bound.InstantiateFrom(bounds_instantiator); 2792 bound = bound.InstantiateFrom(bounds_instantiator);
2784 } 2793 }
2785 if (!type.IsSubtypeOf(bound, malformed_error)) { 2794 if (!malformed_bound_error.IsNull() ||
2795 !type.IsSubtypeOf(bound, malformed_error)) {
2796 // Ignore this bound error if another malformed error was already
2797 // reported for this type test.
2786 if (malformed_error->IsNull()) { 2798 if (malformed_error->IsNull()) {
2787 const String& type_argument_name = String::Handle(type.Name()); 2799 const String& type_argument_name = String::Handle(type.Name());
2788 const String& class_name = String::Handle(cls.Name()); 2800 const String& class_name = String::Handle(cls.Name());
2789 const String& bound_name = String::Handle(bound.Name()); 2801 const String& bound_name = String::Handle(bound.Name());
2790 const Script& script = Script::Handle(cls.script()); 2802 const Script& script = Script::Handle(cls.script());
2791 // Since the bound was canonicalized, its token index was lost, 2803 // Since the bound was canonicalized, its token index was lost,
2792 // therefore, use the token index of the corresponding type parameter. 2804 // therefore, use the token index of the corresponding type parameter.
2793 const TypeArguments& type_parameters = 2805 const TypeArguments& type_parameters =
2794 TypeArguments::Handle(cls.type_parameters()); 2806 TypeArguments::Handle(cls.type_parameters());
2795 type = type_parameters.TypeAt(i); 2807 type = type_parameters.TypeAt(i);
2796 *malformed_error ^= FormatError(script, type.token_index(), 2808 *malformed_error ^= FormatError(malformed_bound_error,
2809 script, type.token_index(),
2797 "type argument '%s' does not " 2810 "type argument '%s' does not "
2798 "extend bound '%s' of '%s'\n", 2811 "extend bound '%s' of '%s'\n",
2799 type_argument_name.ToCString(), 2812 type_argument_name.ToCString(),
2800 bound_name.ToCString(), 2813 bound_name.ToCString(),
2801 class_name.ToCString()); 2814 class_name.ToCString());
2802 } 2815 }
2803 return false; 2816 return false;
2804 } 2817 }
2805 } 2818 }
2806 } 2819 }
(...skipping 6012 matching lines...) Expand 10 before | Expand all | Expand 10 after
8819 result.set_num_args_tested(num_args_tested); 8832 result.set_num_args_tested(num_args_tested);
8820 // Number of array elements in one test entry (num_args_tested + 1) 8833 // Number of array elements in one test entry (num_args_tested + 1)
8821 intptr_t len = result.TestEntryLength(); 8834 intptr_t len = result.TestEntryLength();
8822 // IC data array must be null terminated (sentinel entry). 8835 // IC data array must be null terminated (sentinel entry).
8823 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); 8836 const Array& ic_data = Array::Handle(Array::New(len, Heap::kOld));
8824 result.set_ic_data(ic_data); 8837 result.set_ic_data(ic_data);
8825 return result.raw(); 8838 return result.raw();
8826 } 8839 }
8827 8840
8828 } // namespace dart 8841 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698