Chromium Code Reviews| Index: runtime/vm/parser.cc |
| diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc |
| index 288692c435d3ad2d5fdc6ef014ef31a801982cc4..3c052fc1e3b05f4a85db4d9412dc93d90d84b93d 100644 |
| --- a/runtime/vm/parser.cc |
| +++ b/runtime/vm/parser.cc |
| @@ -435,7 +435,8 @@ struct ParamDesc { |
| metadata(NULL), |
| var(NULL), |
| is_final(false), |
| - is_field_initializer(false) { } |
| + is_field_initializer(false), |
| + has_explicit_type(false) { } |
| const AbstractType* type; |
| intptr_t name_pos; |
| const String* name; |
| @@ -444,6 +445,7 @@ struct ParamDesc { |
| LocalVariable* var; // Scope variable allocated for this parameter. |
| bool is_final; |
| bool is_field_initializer; |
| + bool has_explicit_type; |
| }; |
| @@ -1415,6 +1417,8 @@ void Parser::ParseFormalParameter(bool allow_explicit_default_value, |
| ConsumeToken(); |
| var_seen = true; |
| // The parameter type is the 'dynamic' type. |
| + // If this is an initializing formal, its type will be corrected when the |
| + // constructor is fully parsed. |
|
hausner
2013/10/07 23:03:08
corrected -> set to the type of the respective fie
rmacnak
2013/10/08 01:01:01
Done.
|
| parameter.type = &Type::ZoneHandle(Type::DynamicType()); |
| } |
| if (CurrentToken() == Token::kTHIS) { |
| @@ -1448,10 +1452,13 @@ void Parser::ParseFormalParameter(bool allow_explicit_default_value, |
| // The types of formal parameters are never ignored, even in unchecked |
| // mode, because they are part of the function type of closurized |
| // functions appearing in type tests with typedefs. |
| + parameter.has_explicit_type = true; |
| parameter.type = &AbstractType::ZoneHandle( |
| ParseType(is_top_level_ ? ClassFinalizer::kResolveTypeParameters : |
| ClassFinalizer::kCanonicalize)); |
| } else { |
| + // If this is an initializing formal, its type will be corrected when the |
| + // constructor is fully parsed. |
|
hausner
2013/10/07 23:03:08
ditto
rmacnak
2013/10/08 01:01:01
Done.
|
| parameter.type = &Type::ZoneHandle(Type::DynamicType()); |
| } |
| } |
| @@ -2555,6 +2562,15 @@ SequenceNode* Parser::ParseConstructor(const Function& func, |
| "initializing formal parameters"); |
| } |
| CheckDuplicateFieldInit(param.name_pos, &initialized_fields, &field); |
| + |
| + if (!param.has_explicit_type) { |
| + const AbstractType& field_type = |
| + AbstractType::ZoneHandle(field.type()); |
| + param.type = &field_type; |
| + // Parameter type was already set in diet parsing: overwrite. |
|
hausner
2013/10/07 23:03:08
nit: I don't think we use the term diet parsing in
rmacnak
2013/10/08 01:01:01
Done.
|
| + func.SetParameterTypeAt(i, field_type); |
| + } |
| + |
| AstNode* instance = new LoadLocalNode(param.name_pos, receiver); |
| // Initializing formals cannot be used in the explicit initializer |
| // list, nor can they be used in the constructor body. |