From 9727a4a4ef6a3c3de8cd6be75ab515643ee15bc6 Mon Sep 17 00:00:00 2001 From: Mike Fairhurst Date: Tue, 24 Jul 2018 19:31:57 +0000 Subject: [PATCH] Fix #33415 no error for awaiting a void expression. Bug: 33415 Change-Id: I4d4e81fef79a5bc5162e37ab07a8fe99e50c8dfc Reviewed-on: https://dart-review.googlesource.com/60522 Commit-Queue: Mike Fairhurst Reviewed-by: Brian Wilkerson --- pkg/analyzer/lib/src/generated/error_verifier.dart | 1 + .../generated/static_warning_code_kernel_test.dart | 5 +++++ .../test/generated/static_warning_code_test.dart | 11 +++++++++++ pkg/async_helper/lib/async_helper.dart | 6 ++++-- .../test/incremental_dart2js_load_from_dill_test.dart | 3 ++- tests/co19_2/co19_2-analyzer.status | 3 +++ tools/patch_sdk.dart | 2 +- 7 files changed, 27 insertions(+), 4 deletions(-) diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart index 433f8006543..aaa1caf8bfa 100644 --- a/pkg/analyzer/lib/src/generated/error_verifier.dart +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart @@ -397,6 +397,7 @@ class ErrorVerifier extends RecursiveAstVisitor { _errorReporter.reportErrorForToken( CompileTimeErrorCode.AWAIT_IN_WRONG_CONTEXT, node.awaitKeyword); } + _checkForUseOfVoidResult(node.expression); return super.visitAwaitExpression(node); } diff --git a/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart b/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart index 03948d90ea5..1bb85696c38 100644 --- a/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart +++ b/pkg/analyzer/test/generated/static_warning_code_kernel_test.dart @@ -653,4 +653,9 @@ class StaticWarningCodeTest_Kernel extends StaticWarningCodeTest_Driver { test_useOfVoidResult_variableDeclaration_method_ok() async { return super.test_useOfVoidResult_variableDeclaration_method_ok(); } + + @override + test_useOfVoidResult_await() async { + return super.test_useOfVoidResult_await(); + } } diff --git a/pkg/analyzer/test/generated/static_warning_code_test.dart b/pkg/analyzer/test/generated/static_warning_code_test.dart index 86e6fa7cbd4..ccbe8cda644 100644 --- a/pkg/analyzer/test/generated/static_warning_code_test.dart +++ b/pkg/analyzer/test/generated/static_warning_code_test.dart @@ -5028,4 +5028,15 @@ class S { await computeAnalysisResult(source); assertNoErrors(source); } + + test_useOfVoidResult_await() async { + Source source = addSource(r''' +main() async { + void x; + await x; +}'''); + await computeAnalysisResult(source); + assertErrors(source, [StaticWarningCode.USE_OF_VOID_RESULT]); + verify([source]); + } } diff --git a/pkg/async_helper/lib/async_helper.dart b/pkg/async_helper/lib/async_helper.dart index 46360f93046..961d1d61c72 100644 --- a/pkg/async_helper/lib/async_helper.dart +++ b/pkg/async_helper/lib/async_helper.dart @@ -23,6 +23,8 @@ library async_helper; +import 'dart:async'; + bool _initialized = false; int _asyncLevel = 0; @@ -81,7 +83,7 @@ void asyncSuccess(_) => asyncEnd(); * * [f] must return a [:Future:] for the test computation. */ -void asyncTest(f()) { +Future asyncTest(f()) { asyncStart(); - f().then(asyncSuccess); + return f().then(asyncSuccess); } diff --git a/pkg/front_end/test/incremental_dart2js_load_from_dill_test.dart b/pkg/front_end/test/incremental_dart2js_load_from_dill_test.dart index d9a9cad78dc..ea0190d4b57 100644 --- a/pkg/front_end/test/incremental_dart2js_load_from_dill_test.dart +++ b/pkg/front_end/test/incremental_dart2js_load_from_dill_test.dart @@ -2,6 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:async' show Future; import 'dart:io' show Directory, File; import 'package:expect/expect.dart' show Expect; @@ -22,7 +23,7 @@ main() async { } } -void testDart2jsCompile() async { +Future testDart2jsCompile() async { final Uri dart2jsUrl = Uri.base.resolve("pkg/compiler/bin/dart2js.dart"); final Uri invalidateUri = Uri.parse("package:compiler/src/filenames.dart"); Uri normalDill = outDir.uri.resolve("dart2js.full.dill"); diff --git a/tests/co19_2/co19_2-analyzer.status b/tests/co19_2/co19_2-analyzer.status index d94473f8324..bbb17dd2d40 100644 --- a/tests/co19_2/co19_2-analyzer.status +++ b/tests/co19_2/co19_2-analyzer.status @@ -2782,6 +2782,9 @@ LibTest/io/RandomAccessFile/writeString_A01_t02: CompileTimeError # Dart 1 const LibTest/io/RandomAccessFile/writeString_A01_t03: CompileTimeError # Dart 1 constants, https://github.com/dart-lang/sdk/issues/33894 LibTest/io/Stdin/readLineSync_A03_t01: CompileTimeError # Dart 1 constants, https://github.com/dart-lang/sdk/issues/33894 LibTest/io/Stdin/readLineSync_A03_t02: CompileTimeError # Dart 1 constants, https://github.com/dart-lang/sdk/issues/33894 +LibTest/io/Stdin/readLineSync_A03_t03: CompileTimeError # Erroneously awaits void +LibTest/io/Stdin/readLineSync_A03_t04: CompileTimeError # Erroneously awaits void +LibTest/io/Stdin/readLineSync_A04_t01: CompileTimeError # Erroneously awaits void LibTest/io/Stdout/add_A02_t01: CompileTimeError # Dart 1 constants, https://github.com/dart-lang/sdk/issues/33894 LibTest/io/Stdout/encoding_A01_t01: CompileTimeError # Dart 1 constants, https://github.com/dart-lang/sdk/issues/33894 LibTest/io/Stdout/writeAll_A01_t02: CompileTimeError # Dart 1 constants, https://github.com/dart-lang/sdk/issues/33894 diff --git a/tools/patch_sdk.dart b/tools/patch_sdk.dart index e32065cb4ef..b4ca60d287b 100644 --- a/tools/patch_sdk.dart +++ b/tools/patch_sdk.dart @@ -146,7 +146,7 @@ Future _main(List argv) async { throw "Unknown mode: $mode"; } - await _writeSync( + _writeSync( librariesJson.toFilePath(), jsonEncode({ mode: {"libraries": locations}