Chromium Code Reviews| Index: runtime/vm/parser.cc |
| diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc |
| index ed380ad07b6b60f402cf15135798681e2118ce75..c5f95363f9a05253d2838dc680e72d83cfd0412d 100644 |
| --- a/runtime/vm/parser.cc |
| +++ b/runtime/vm/parser.cc |
| @@ -244,6 +244,7 @@ Parser::Parser(const Script& script, const Library& library, intptr_t token_pos) |
| token_kind_(Token::kILLEGAL), |
| current_block_(NULL), |
| is_top_level_(false), |
| + parsing_metadata_(false), |
| current_member_(NULL), |
| allow_function_literals_(true), |
| parsed_function_(NULL), |
| @@ -270,6 +271,7 @@ Parser::Parser(const Script& script, |
| token_kind_(Token::kILLEGAL), |
| current_block_(NULL), |
| is_top_level_(false), |
| + parsing_metadata_(false), |
| current_member_(NULL), |
| allow_function_literals_(true), |
| parsed_function_(parsed_function), |
| @@ -859,6 +861,7 @@ RawObject* Parser::ParseMetadata(const Class& cls, intptr_t token_pos) { |
| const Library& lib = Library::Handle(cls.library()); |
| Parser parser(script, lib, token_pos); |
| parser.set_current_class(cls); |
| + parser.set_parsing_metadata(true); |
| return parser.EvaluateMetadata(); |
| } else { |
| Error& error = Error::Handle(); |
| @@ -8247,7 +8250,8 @@ AstNode* Parser::LoadFieldIfUnresolved(AstNode* node) { |
| // In an instance method, we convert this into a getter call |
| // for a field (which may be defined in a subclass.) |
| String& name = String::CheckedZoneHandle(primary->primary().raw()); |
| - if (current_function().is_static() || |
| + if (parsing_metadata_ || |
|
hausner
2013/11/19 00:07:24
Please add to the comment above why we distinguish
rmacnak
2013/11/19 01:01:24
Rewrote as a more intention-revealing error path a
|
| + current_function().is_static() || |
| current_function().IsInFactoryScope()) { |
| return new StaticGetterNode(primary->token_pos(), |
| NULL, // No receiver. |
| @@ -8274,6 +8278,11 @@ AstNode* Parser::LoadClosure(PrimaryNode* primary) { |
| closure = CreateImplicitClosureNode(func, primary->token_pos(), NULL); |
| } else { |
| // Instance function access. |
| + if (parsing_metadata_) { |
| + ErrorMsg(primary->token_pos(), |
| + "cannot access instance method '%s' from metadata", |
| + funcname.ToCString()); |
| + } |
| if (current_function().is_static() || |
| current_function().IsInFactoryScope()) { |
| ErrorMsg(primary->token_pos(), |
| @@ -8656,6 +8665,11 @@ void Parser::CheckInstanceFieldAccess(intptr_t field_pos, |
| const String& field_name) { |
| // Fields are not accessible from a static function, except from a |
| // constructor, which is considered as non-static by the compiler. |
| + if (parsing_metadata_) { |
| + ErrorMsg(field_pos, |
| + "cannot access instance field '%s' from metadata", |
| + field_name.ToCString()); |
| + } |
| if (current_function().is_static()) { |
| ErrorMsg(field_pos, |
| "cannot access instance field '%s' from a static function", |