@@ -2012,7 +2012,7 @@ void Parser::ParseParameterType(ParamList* params) {
2012
2012
// It is too early to resolve the type here, since it can be a result type
2013
2013
// referring to a not yet declared function type parameter.
2014
2014
parameter.type = &AbstractType::ZoneHandle(
2015
- Z, ParseTypeOrFunctionType(false , ClassFinalizer::kDoNotResolve));
2015
+ Z, ParseTypeOrFunctionType(true , ClassFinalizer::kDoNotResolve));
2016
2016
2017
2017
// At this point, we must see an identifier for the parameter name, unless
2018
2018
// we are using the function type syntax (in which case the name is optional,
@@ -2060,10 +2060,6 @@ void Parser::ParseParameterType(ParamList* params) {
2060
2060
ASSERT(params->num_optional_parameters == 0);
2061
2061
}
2062
2062
}
2063
- if (parameter.type->IsVoidType()) {
2064
- ReportError("parameter '%s' may not be 'void'",
2065
- parameter.name->ToCString());
2066
- }
2067
2063
if (params->implicitly_final) {
2068
2064
parameter.is_final = true;
2069
2065
}
@@ -2287,10 +2283,6 @@ void Parser::ParseFormalParameter(bool allow_explicit_default_value,
2287
2283
ASSERT(params->num_optional_parameters == 0);
2288
2284
}
2289
2285
}
2290
- if (parameter.type->IsVoidType()) {
2291
- ReportError("parameter '%s' may not be 'void'",
2292
- parameter.name->ToCString());
2293
- }
2294
2286
if (params->implicitly_final) {
2295
2287
parameter.is_final = true;
2296
2288
}
@@ -4756,8 +4748,6 @@ void Parser::ParseClassMemberDefinition(ClassDesc* members,
4756
4748
"missing 'var', 'final', 'const' or type"
4757
4749
" in field declaration");
4758
4750
}
4759
- } else if (member.type->IsVoidType()) {
4760
- ReportError(member.name_pos, "field may not be 'void'");
4761
4751
}
4762
4752
if (!member.type->IsResolved()) {
4763
4753
AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw());
@@ -8003,7 +7993,7 @@ RawAbstractType* Parser::ParseConstFinalVarOrType(
8003
7993
type_is_optional = true;
8004
7994
}
8005
7995
if ((CurrentToken() == Token::kVOID) || IsFunctionTypeSymbol()) {
8006
- return ParseFunctionType(AbstractType::Handle(Z) , finalization);
7996
+ return ParseTypeOrFunctionType(true , finalization);
8007
7997
}
8008
7998
if (CurrentToken() != Token::kIDENT) {
8009
7999
if (type_is_optional) {
@@ -8023,7 +8013,7 @@ RawAbstractType* Parser::ParseConstFinalVarOrType(
8023
8013
return Type::DynamicType();
8024
8014
}
8025
8015
}
8026
- return ParseTypeOrFunctionType(false, finalization);
8016
+ return ParseTypeOrFunctionType(false, finalization); // void handled above.
8027
8017
}
8028
8018
8029
8019
// Returns ast nodes of the variable initialization. Variables without an
@@ -8480,6 +8470,8 @@ bool Parser::TryParseQualIdent() {
8480
8470
// Allow 'void' as type if 'allow_void' is true.
8481
8471
// Note that 'void Function()' is always allowed, since it is a function type
8482
8472
// and not the void type.
8473
+ // TODO(regis): Consider removing allow_void argument, since this call is only
8474
+ // used where void is allowed. Wait for Dart 2 spec to stabilize.
8483
8475
bool Parser::TryParseType(bool allow_void) {
8484
8476
bool found = false;
8485
8477
if (CurrentToken() == Token::kVOID) {
@@ -8536,8 +8528,7 @@ bool Parser::IsVariableDeclaration() {
8536
8528
}
8537
8529
if ((CurrentToken() != Token::kIDENT) && (CurrentToken() != Token::kVOID) &&
8538
8530
(CurrentToken() != Token::kCONST)) {
8539
- // Not a legal type identifier or void (result type of function type)
8540
- // or const keyword or metadata.
8531
+ // Not a legal type identifier or void or const keyword or metadata.
8541
8532
return false;
8542
8533
}
8543
8534
const TokenPosition saved_pos = TokenPos();
@@ -8548,7 +8539,7 @@ bool Parser::IsVariableDeclaration() {
8548
8539
have_type = true; // Type is dynamic if 'const' is not followed by a type.
8549
8540
}
8550
8541
if ((CurrentToken() == Token::kVOID) || IsFunctionTypeSymbol()) {
8551
- if (TryParseType(false )) {
8542
+ if (TryParseType(true )) {
8552
8543
have_type = true;
8553
8544
}
8554
8545
} else if (IsIdentifier()) { // Type or variable name.
@@ -8558,7 +8549,7 @@ bool Parser::IsVariableDeclaration() {
8558
8549
Token::IsIdentifier(follower)) { // Variable name following a type.
8559
8550
// We see the beginning of something that could be a type.
8560
8551
const TokenPosition type_pos = TokenPos();
8561
- if (TryParseType(false)) {
8552
+ if (TryParseType(false)) { // void handled above.
8562
8553
have_type = true;
8563
8554
} else {
8564
8555
SetPosition(type_pos);
@@ -8685,10 +8676,12 @@ bool Parser::IsForInStatement() {
8685
8676
CurrentToken() == Token::kCONST) {
8686
8677
ConsumeToken();
8687
8678
}
8688
- if (IsIdentifier()) {
8689
- if (LookaheadToken(1) == Token::kIN) {
8679
+ // void as the loop variable type does not make much sense, but it is not
8680
+ // disallowed by the spec.
8681
+ if (IsIdentifier() || (CurrentToken() == Token::kVOID)) {
8682
+ if ((CurrentToken() != Token::kVOID) && (LookaheadToken(1) == Token::kIN)) {
8690
8683
return true;
8691
- } else if (TryParseType(false )) {
8684
+ } else if (TryParseType(true )) {
8692
8685
if (IsIdentifier()) {
8693
8686
ConsumeToken();
8694
8687
}
0 commit comments