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

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

Issue 13992002: Prohibit use of dynamic when extending or implementing classes (was crashing). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 8 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') | tests/language/dynamic2_test.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) 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 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 3053 matching lines...) Expand 10 before | Expand all | Expand 10 after
3064 member.name_pos = TokenPos(); 3064 member.name_pos = TokenPos();
3065 member.name = CurrentLiteral(); // Unqualified identifier. 3065 member.name = CurrentLiteral(); // Unqualified identifier.
3066 ConsumeToken(); 3066 ConsumeToken();
3067 if (member.has_factory) { 3067 if (member.has_factory) {
3068 // The factory name may be qualified, but the first identifier must match 3068 // The factory name may be qualified, but the first identifier must match
3069 // the name of the immediately enclosing class. 3069 // the name of the immediately enclosing class.
3070 if (!member.name->Equals(members->class_name())) { 3070 if (!member.name->Equals(members->class_name())) {
3071 ErrorMsg(member.name_pos, "factory name must be '%s'", 3071 ErrorMsg(member.name_pos, "factory name must be '%s'",
3072 members->class_name().ToCString()); 3072 members->class_name().ToCString());
3073 } 3073 }
3074 // Do not bypass class resolution by using current_class() directly, since
3075 // it may be a patch class.
3074 const Object& result_type_class = Object::Handle( 3076 const Object& result_type_class = Object::Handle(
3075 UnresolvedClass::New(LibraryPrefix::Handle(), 3077 UnresolvedClass::New(LibraryPrefix::Handle(),
3076 *member.name, 3078 *member.name,
3077 member.name_pos)); 3079 member.name_pos));
3078 // The type arguments of the result type are set during finalization. 3080 // The type arguments of the result type are the type parameters of the
3079 member.type = &Type::ZoneHandle(Type::New(result_type_class, 3081 // current class. Note that in the case of a patch class, they are copied
3080 TypeArguments::Handle(), 3082 // from the class being patched.
3081 member.name_pos)); 3083 member.type = &Type::ZoneHandle(Type::New(
3084 result_type_class,
3085 TypeArguments::Handle(current_class().type_parameters()),
3086 member.name_pos));
3082 } else if (member.has_static) { 3087 } else if (member.has_static) {
3083 ErrorMsg(member.name_pos, "constructor cannot be static"); 3088 ErrorMsg(member.name_pos, "constructor cannot be static");
3084 } 3089 }
3085 // We must be dealing with a constructor or named constructor. 3090 // We must be dealing with a constructor or named constructor.
3086 member.kind = RawFunction::kConstructor; 3091 member.kind = RawFunction::kConstructor;
3087 *member.name = String::Concat(*member.name, Symbols::Dot()); 3092 *member.name = String::Concat(*member.name, Symbols::Dot());
3088 if (CurrentToken() == Token::kPERIOD) { 3093 if (CurrentToken() == Token::kPERIOD) {
3089 // Named constructor. 3094 // Named constructor.
3090 ConsumeToken(); 3095 ConsumeToken();
3091 member.constructor_name = ExpectIdentifier("identifier expected"); 3096 member.constructor_name = ExpectIdentifier("identifier expected");
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
3294 if (CurrentToken() == Token::kEXTENDS) { 3299 if (CurrentToken() == Token::kEXTENDS) {
3295 ConsumeToken(); 3300 ConsumeToken();
3296 const intptr_t type_pos = TokenPos(); 3301 const intptr_t type_pos = TokenPos();
3297 super_type = ParseType(ClassFinalizer::kTryResolve); 3302 super_type = ParseType(ClassFinalizer::kTryResolve);
3298 if (super_type.IsTypeParameter()) { 3303 if (super_type.IsTypeParameter()) {
3299 ErrorMsg(type_pos, 3304 ErrorMsg(type_pos,
3300 "class '%s' may not extend type parameter '%s'", 3305 "class '%s' may not extend type parameter '%s'",
3301 class_name.ToCString(), 3306 class_name.ToCString(),
3302 String::Handle(super_type.UserVisibleName()).ToCString()); 3307 String::Handle(super_type.UserVisibleName()).ToCString());
3303 } 3308 }
3309 if (super_type.IsDynamicType()) {
3310 ErrorMsg(type_pos,
3311 "class '%s' may not extend dynamic",
hausner 2013/04/10 14:53:53 may not extend 'dynamic'? I'm fine either way.
regis 2013/04/10 16:31:33 Done.
3312 class_name.ToCString());
3313 }
3304 if (CurrentToken() == Token::kWITH) { 3314 if (CurrentToken() == Token::kWITH) {
3305 super_type = ParseMixins(super_type); 3315 super_type = ParseMixins(super_type);
3306 } 3316 }
3307 } else { 3317 } else {
3308 // No extends clause: implicitly extend Object. 3318 // No extends clause: implicitly extend Object.
3309 super_type = Type::ObjectType(); 3319 super_type = Type::ObjectType();
3310 } 3320 }
3311 ASSERT(!super_type.IsNull()); 3321 ASSERT(!super_type.IsNull());
3312 cls.set_super_type(super_type); 3322 cls.set_super_type(super_type);
3313 3323
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
3835 // Now parse and add the new interfaces. 3845 // Now parse and add the new interfaces.
3836 do { 3846 do {
3837 ConsumeToken(); 3847 ConsumeToken();
3838 intptr_t interface_pos = TokenPos(); 3848 intptr_t interface_pos = TokenPos();
3839 interface = ParseType(ClassFinalizer::kTryResolve); 3849 interface = ParseType(ClassFinalizer::kTryResolve);
3840 if (interface.IsTypeParameter()) { 3850 if (interface.IsTypeParameter()) {
3841 ErrorMsg(interface_pos, 3851 ErrorMsg(interface_pos,
3842 "type parameter '%s' may not be used in interface list", 3852 "type parameter '%s' may not be used in interface list",
3843 String::Handle(interface.UserVisibleName()).ToCString()); 3853 String::Handle(interface.UserVisibleName()).ToCString());
3844 } 3854 }
3855 if (interface.IsDynamicType()) {
3856 ErrorMsg(interface_pos, "dynamic may not be used in interface list");
hausner 2013/04/10 14:53:53 ditto
regis 2013/04/10 16:31:33 Done.
3857 }
3845 all_interfaces.Add(interface); 3858 all_interfaces.Add(interface);
3846 } while (CurrentToken() == Token::kCOMMA); 3859 } while (CurrentToken() == Token::kCOMMA);
3847 cls_interfaces = Array::MakeArray(all_interfaces); 3860 cls_interfaces = Array::MakeArray(all_interfaces);
3848 cls.set_interfaces(cls_interfaces); 3861 cls.set_interfaces(cls_interfaces);
3849 } 3862 }
3850 3863
3851 3864
3852 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) { 3865 RawAbstractType* Parser::ParseMixins(const AbstractType& super_type) {
3853 TRACE_PARSER("ParseMixins"); 3866 TRACE_PARSER("ParseMixins");
3854 ASSERT(CurrentToken() == Token::kWITH); 3867 ASSERT(CurrentToken() == Token::kWITH);
(...skipping 6049 matching lines...) Expand 10 before | Expand all | Expand 10 after
9904 void Parser::SkipQualIdent() { 9917 void Parser::SkipQualIdent() {
9905 ASSERT(IsIdentifier()); 9918 ASSERT(IsIdentifier());
9906 ConsumeToken(); 9919 ConsumeToken();
9907 if (CurrentToken() == Token::kPERIOD) { 9920 if (CurrentToken() == Token::kPERIOD) {
9908 ConsumeToken(); // Consume the kPERIOD token. 9921 ConsumeToken(); // Consume the kPERIOD token.
9909 ExpectIdentifier("identifier expected after '.'"); 9922 ExpectIdentifier("identifier expected after '.'");
9910 } 9923 }
9911 } 9924 }
9912 9925
9913 } // namespace dart 9926 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | tests/language/dynamic2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698