Skip to content

Commit ed1d8bd

Browse files
creliercommit-bot@chromium.org
authored andcommitted
[VM parser] Complete support for generalized void (fixes #30516).
'void' is now allowed as type annotation for locals, fields, and formal parameters, in addition to being previously allowed as type argument. Update status files. Change-Id: I6459f56824dc0a695615d8dc87c9a8a1f9be29ef Reviewed-on: https://dart-review.googlesource.com/37651 Reviewed-by: Siva Annamalai <[email protected]> Commit-Queue: Régis Crelier <[email protected]>
1 parent ddafb88 commit ed1d8bd

File tree

6 files changed

+20
-25
lines changed

6 files changed

+20
-25
lines changed

runtime/vm/parser.cc

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ void Parser::ParseParameterType(ParamList* params) {
20122012
// It is too early to resolve the type here, since it can be a result type
20132013
// referring to a not yet declared function type parameter.
20142014
parameter.type = &AbstractType::ZoneHandle(
2015-
Z, ParseTypeOrFunctionType(false, ClassFinalizer::kDoNotResolve));
2015+
Z, ParseTypeOrFunctionType(true, ClassFinalizer::kDoNotResolve));
20162016

20172017
// At this point, we must see an identifier for the parameter name, unless
20182018
// we are using the function type syntax (in which case the name is optional,
@@ -2060,10 +2060,6 @@ void Parser::ParseParameterType(ParamList* params) {
20602060
ASSERT(params->num_optional_parameters == 0);
20612061
}
20622062
}
2063-
if (parameter.type->IsVoidType()) {
2064-
ReportError("parameter '%s' may not be 'void'",
2065-
parameter.name->ToCString());
2066-
}
20672063
if (params->implicitly_final) {
20682064
parameter.is_final = true;
20692065
}
@@ -2287,10 +2283,6 @@ void Parser::ParseFormalParameter(bool allow_explicit_default_value,
22872283
ASSERT(params->num_optional_parameters == 0);
22882284
}
22892285
}
2290-
if (parameter.type->IsVoidType()) {
2291-
ReportError("parameter '%s' may not be 'void'",
2292-
parameter.name->ToCString());
2293-
}
22942286
if (params->implicitly_final) {
22952287
parameter.is_final = true;
22962288
}
@@ -4756,8 +4748,6 @@ void Parser::ParseClassMemberDefinition(ClassDesc* members,
47564748
"missing 'var', 'final', 'const' or type"
47574749
" in field declaration");
47584750
}
4759-
} else if (member.type->IsVoidType()) {
4760-
ReportError(member.name_pos, "field may not be 'void'");
47614751
}
47624752
if (!member.type->IsResolved()) {
47634753
AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw());
@@ -8003,7 +7993,7 @@ RawAbstractType* Parser::ParseConstFinalVarOrType(
80037993
type_is_optional = true;
80047994
}
80057995
if ((CurrentToken() == Token::kVOID) || IsFunctionTypeSymbol()) {
8006-
return ParseFunctionType(AbstractType::Handle(Z), finalization);
7996+
return ParseTypeOrFunctionType(true, finalization);
80077997
}
80087998
if (CurrentToken() != Token::kIDENT) {
80097999
if (type_is_optional) {
@@ -8023,7 +8013,7 @@ RawAbstractType* Parser::ParseConstFinalVarOrType(
80238013
return Type::DynamicType();
80248014
}
80258015
}
8026-
return ParseTypeOrFunctionType(false, finalization);
8016+
return ParseTypeOrFunctionType(false, finalization); // void handled above.
80278017
}
80288018

80298019
// Returns ast nodes of the variable initialization. Variables without an
@@ -8480,6 +8470,8 @@ bool Parser::TryParseQualIdent() {
84808470
// Allow 'void' as type if 'allow_void' is true.
84818471
// Note that 'void Function()' is always allowed, since it is a function type
84828472
// 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.
84838475
bool Parser::TryParseType(bool allow_void) {
84848476
bool found = false;
84858477
if (CurrentToken() == Token::kVOID) {
@@ -8536,8 +8528,7 @@ bool Parser::IsVariableDeclaration() {
85368528
}
85378529
if ((CurrentToken() != Token::kIDENT) && (CurrentToken() != Token::kVOID) &&
85388530
(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.
85418532
return false;
85428533
}
85438534
const TokenPosition saved_pos = TokenPos();
@@ -8548,7 +8539,7 @@ bool Parser::IsVariableDeclaration() {
85488539
have_type = true; // Type is dynamic if 'const' is not followed by a type.
85498540
}
85508541
if ((CurrentToken() == Token::kVOID) || IsFunctionTypeSymbol()) {
8551-
if (TryParseType(false)) {
8542+
if (TryParseType(true)) {
85528543
have_type = true;
85538544
}
85548545
} else if (IsIdentifier()) { // Type or variable name.
@@ -8558,7 +8549,7 @@ bool Parser::IsVariableDeclaration() {
85588549
Token::IsIdentifier(follower)) { // Variable name following a type.
85598550
// We see the beginning of something that could be a type.
85608551
const TokenPosition type_pos = TokenPos();
8561-
if (TryParseType(false)) {
8552+
if (TryParseType(false)) { // void handled above.
85628553
have_type = true;
85638554
} else {
85648555
SetPosition(type_pos);
@@ -8685,10 +8676,12 @@ bool Parser::IsForInStatement() {
86858676
CurrentToken() == Token::kCONST) {
86868677
ConsumeToken();
86878678
}
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)) {
86908683
return true;
8691-
} else if (TryParseType(false)) {
8684+
} else if (TryParseType(true)) {
86928685
if (IsIdentifier()) {
86938686
ConsumeToken();
86948687
}

tests/co19/co19-runtime.status

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t09: Runtime
300300
Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_async_t10: RuntimeError # Issue 25748
301301
Language/Statements/Yield_and_Yield_Each/Yield_Each/execution_sync_t05: RuntimeError # Issue 25662,25634
302302
Language/Types/Type_Void/syntax_t01: MissingCompileTimeError # Issue co19/30264
303+
Language/Types/Type_Void/syntax_t02: MissingCompileTimeError # Issue co19/30264
304+
Language/Types/Type_Void/syntax_t04: MissingCompileTimeError # Issue co19/30264
305+
Language/Types/Type_Void/syntax_t09: MissingCompileTimeError # Issue co19/30264
303306
LayoutTests/fast/*: SkipByDesign # DOM not supported on VM.
304307
LibTest/collection/ListBase/ListBase_class_A01_t01: RuntimeError # Large integers
305308
LibTest/collection/ListMixin/ListMixin_class_A01_t01: RuntimeError # Large integers

tests/language/language.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ duplicate_export_negative_test: Fail # Issue 6134
424424
example_constructor_test: Fail, OK # Failures related to super call in ctor initializer list
425425
field_initialization_order_test: Fail, OK # Failures related to super call in ctor initializer list
426426
final_field_initialization_order_test: Fail, OK # Failures related to super call in ctor initializer list
427-
generalized_void_syntax_test: CompileTimeError
428427
generic_methods_type_expression_test: RuntimeError # Issue 25869 / 27460
429428
least_upper_bound_expansive_test/*: Fail, OK # Non-contractive types are not supported in the vm.
430429
main_not_a_function_test/01: Skip # Skipped temporaril until Issue 29895 is fixed.

tests/language_2/language_2_flutter.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ factory6_test/00: CompileTimeError
8585
field_increment_bailout_test: CompileTimeError
8686
field_override_test/01: CompileTimeError
8787
function_malformed_result_type_test: CompileTimeError
88-
generalized_void_syntax_test: CompileTimeError # Issue #30176
8988
generic_function_typedef2_test/04: CompileTimeError
9089
instance_creation_in_function_annotation_test: CompileTimeError
9190
internal_library_test/01: CompileTimeError

tests/language_2/language_2_precompiled.status

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ function_type_call_getter2_test/04: MissingCompileTimeError
376376
function_type_call_getter2_test/05: MissingCompileTimeError
377377
fuzzy_arrows_test/01: MissingCompileTimeError
378378
fuzzy_arrows_test/03: RuntimeError
379-
generalized_void_syntax_test: CompileTimeError # Issue #30176
380379
generic_closure_test: RuntimeError
381380
generic_constructor_mixin2_test/01: MissingCompileTimeError
382381
generic_constructor_mixin3_test/01: MissingCompileTimeError
@@ -884,6 +883,8 @@ switch_fallthru_test/01: MissingCompileTimeError
884883
symbol_literal_test/01: MissingCompileTimeError
885884
sync_generator1_test/01: MissingCompileTimeError
886885
syntax_test/59: MissingCompileTimeError, OK # Issue 30516.
886+
syntax_test/60: MissingCompileTimeError, OK # Issue 30516.
887+
syntax_test/61: MissingCompileTimeError, OK # Issue 30516.
887888
top_level_getter_no_setter1_test: MissingCompileTimeError
888889
top_level_getter_no_setter2_test: MissingCompileTimeError
889890
transitive_private_library_access_test: MissingCompileTimeError

tests/language_2/language_2_vm.status

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ dynamic_prefix_core_test/01: RuntimeError # Issue 12478
5656
example_constructor_test: Fail, OK
5757
export_ambiguous_main_negative_test: Fail # Issue 14763
5858
field_initialization_order_test: Fail, OK
59-
generalized_void_syntax_test: CompileTimeError # Issue #30176
6059
hello_dart_test: Skip # Incompatible flag: --compile_all
6160
language_2/least_upper_bound_expansive_test/none: CompileTimeError
6261
library_env_test/has_html_support: RuntimeError, OK
@@ -856,6 +855,8 @@ switch_fallthru_test/01: MissingCompileTimeError
856855
symbol_literal_test/01: MissingCompileTimeError
857856
sync_generator1_test/01: MissingCompileTimeError
858857
syntax_test/59: MissingCompileTimeError, OK # Issue 30516.
858+
syntax_test/60: MissingCompileTimeError, OK # Issue 30516.
859+
syntax_test/61: MissingCompileTimeError, OK # Issue 30516.
859860
top_level_getter_no_setter1_test: MissingCompileTimeError
860861
top_level_getter_no_setter2_test: MissingCompileTimeError
861862
transitive_private_library_access_test: MissingCompileTimeError
@@ -1222,7 +1223,6 @@ dynamic_prefix_core_test/01: RuntimeError # Issue 12478
12221223
example_constructor_test: Fail, OK
12231224
export_ambiguous_main_negative_test: Fail # Issue 14763
12241225
field_initialization_order_test: Fail, OK
1225-
generalized_void_syntax_test: CompileTimeError # Issue #30176
12261226
generic_methods_bounds_test/02: MissingRuntimeError
12271227
library_env_test/has_html_support: RuntimeError, OK
12281228
library_env_test/has_no_io_support: RuntimeError, OK

0 commit comments

Comments
 (0)