OLD | NEW |
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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 // parsed type arguments. | 831 // parsed type arguments. |
832 AbstractTypeArguments& arguments = | 832 AbstractTypeArguments& arguments = |
833 AbstractTypeArguments::Handle(parameterized_type.arguments()); | 833 AbstractTypeArguments::Handle(parameterized_type.arguments()); |
834 if (!arguments.IsNull()) { | 834 if (!arguments.IsNull()) { |
835 intptr_t num_arguments = arguments.Length(); | 835 intptr_t num_arguments = arguments.Length(); |
836 AbstractType& type_argument = AbstractType::Handle(); | 836 AbstractType& type_argument = AbstractType::Handle(); |
837 for (intptr_t i = 0; i < num_arguments; i++) { | 837 for (intptr_t i = 0; i < num_arguments; i++) { |
838 type_argument = arguments.TypeAt(i); | 838 type_argument = arguments.TypeAt(i); |
839 type_argument = FinalizeType(cls, type_argument, finalization); | 839 type_argument = FinalizeType(cls, type_argument, finalization); |
840 if (type_argument.IsMalformed()) { | 840 if (type_argument.IsMalformed()) { |
841 // Malformed type arguments to a constructor of a generic type are | |
842 // reported as a compile-time error. | |
843 if (finalization >= kCanonicalizeForCreation) { | |
844 const Script& script = Script::Handle(cls.script()); | |
845 const String& type_name = | |
846 String::Handle(parameterized_type.UserVisibleName()); | |
847 ReportError(script, parameterized_type.token_pos(), | |
848 "type '%s' has malformed type argument", | |
849 type_name.ToCString()); | |
850 } | |
851 // In production mode, malformed type arguments are mapped to dynamic. | 841 // In production mode, malformed type arguments are mapped to dynamic. |
852 // In checked mode, a type with malformed type arguments is malformed. | 842 // In checked mode, a type with malformed type arguments is malformed. |
853 if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) { | 843 if (FLAG_enable_type_checks || FLAG_error_on_malformed_type) { |
854 const Error& error = Error::Handle(type_argument.malformed_error()); | 844 const Error& error = Error::Handle(type_argument.malformed_error()); |
855 const String& type_name = | 845 const String& type_name = |
856 String::Handle(parameterized_type.UserVisibleName()); | 846 String::Handle(parameterized_type.UserVisibleName()); |
857 FinalizeMalformedType(error, cls, parameterized_type, finalization, | 847 FinalizeMalformedType(error, cls, parameterized_type, finalization, |
858 "type '%s' has malformed type argument", | 848 "type '%s' has malformed type argument", |
859 type_name.ToCString()); | 849 type_name.ToCString()); |
860 return parameterized_type.raw(); | 850 return parameterized_type.raw(); |
861 } else { | 851 } else { |
862 type_argument = Type::DynamicType(); | 852 type_argument = Type::DynamicType(); |
863 } | 853 } |
864 } | 854 } |
865 arguments.SetTypeAt(i, type_argument); | 855 arguments.SetTypeAt(i, type_argument); |
866 } | 856 } |
867 } | 857 } |
868 | 858 |
869 // The finalized type argument vector needs num_type_arguments types. | 859 // The finalized type argument vector needs num_type_arguments types. |
870 const intptr_t num_type_arguments = type_class.NumTypeArguments(); | 860 const intptr_t num_type_arguments = type_class.NumTypeArguments(); |
871 // The type class has num_type_parameters type parameters. | 861 // The type class has num_type_parameters type parameters. |
872 const intptr_t num_type_parameters = type_class.NumTypeParameters(); | 862 const intptr_t num_type_parameters = type_class.NumTypeParameters(); |
873 | 863 |
874 // Initialize the type argument vector. | 864 // Initialize the type argument vector. |
875 // Check the number of parsed type arguments, if any. | 865 // Check the number of parsed type arguments, if any. |
876 // Specifying no type arguments indicates a raw type, which is not an error. | 866 // Specifying no type arguments indicates a raw type, which is not an error. |
877 // However, type parameter bounds are checked below, even for a raw type. | 867 // However, type parameter bounds are checked below, even for a raw type. |
878 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { | 868 if (!arguments.IsNull() && (arguments.Length() != num_type_parameters)) { |
879 // Wrong number of type arguments. The type is malformed. | 869 // Wrong number of type arguments. The type is malformed. |
880 if (finalization >= kCanonicalizeForCreation) { | 870 if (finalization >= kCanonicalizeExpression) { |
881 const Script& script = Script::Handle(cls.script()); | 871 const Script& script = Script::Handle(cls.script()); |
882 const String& type_name = | 872 const String& type_name = |
883 String::Handle(parameterized_type.UserVisibleName()); | 873 String::Handle(parameterized_type.UserVisibleName()); |
884 ReportError(script, parameterized_type.token_pos(), | 874 ReportError(script, parameterized_type.token_pos(), |
885 "wrong number of type arguments in type '%s'", | 875 "wrong number of type arguments in type '%s'", |
886 type_name.ToCString()); | 876 type_name.ToCString()); |
887 } | 877 } |
888 FinalizeMalformedType( | 878 FinalizeMalformedType( |
889 Error::Handle(), // No previous error. | 879 Error::Handle(), // No previous error. |
890 cls, parameterized_type, finalization, | 880 cls, parameterized_type, finalization, |
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 void ClassFinalizer::ReportError(const char* format, ...) { | 1687 void ClassFinalizer::ReportError(const char* format, ...) { |
1698 va_list args; | 1688 va_list args; |
1699 va_start(args, format); | 1689 va_start(args, format); |
1700 const Error& error = Error::Handle( | 1690 const Error& error = Error::Handle( |
1701 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); | 1691 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); |
1702 va_end(args); | 1692 va_end(args); |
1703 ReportError(error); | 1693 ReportError(error); |
1704 } | 1694 } |
1705 | 1695 |
1706 } // namespace dart | 1696 } // namespace dart |
OLD | NEW |