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

Unified Diff: runtime/vm/parser.cc

Issue 10910079: Catch illegally declared constructors (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/bad_constructor_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 11841)
+++ runtime/vm/parser.cc (working copy)
@@ -2331,8 +2331,8 @@
if (method->has_const && !(method->IsConstructor() || method->IsFactory())) {
ErrorMsg(method->name_pos, "'const' not allowed for methods");
}
- if (method->IsConstructor() && method->has_static) {
- ErrorMsg(method->name_pos, "constructor cannot be 'static'");
+ if (method->IsFactoryOrConstructor() && method->has_abstract) {
+ ErrorMsg(method->name_pos, "constructor cannot be abstract");
}
if (method->IsConstructor() && method->has_const) {
Class& cls = Class::ZoneHandle(library_.LookupClass(members->class_name()));
@@ -2789,6 +2789,9 @@
member.type = &Type::ZoneHandle(Type::DynamicType());
} else if (CurrentToken() == Token::kFACTORY) {
ConsumeToken();
+ if (member.has_static) {
+ ErrorMsg("factory method cannot be explicitly marked static");
+ }
member.has_factory = true;
member.has_static = true;
// The result type depends on the name of the factory method.
@@ -2849,6 +2852,9 @@
TypeArguments::Handle(),
factory_name.ident_pos));
} else {
+ if (member.has_static) {
+ ErrorMsg("constructor cannot be static");
+ }
member.name_pos = TokenPos();
member.name = CurrentLiteral();
ConsumeToken();
« no previous file with comments | « no previous file | tests/language/bad_constructor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698