From 9c340f9eb18cba1b2c2dc5a57b3909d2dc47cde5 Mon Sep 17 00:00:00 2001 From: Dmitry Stefantsov Date: Wed, 1 Mar 2017 16:44:52 +0100 Subject: [PATCH] Revert last 4 commits by @lrn Reverted commits: * ef097edad6e5e4e82c3891ad2d8f9cde8fa8cfdc. ("Make Analyzer, VM and dart2js accept URI strings as part-of library identifier.") * e8e1857814c2c0d9ae2c5431f89a84523667259b. ("Fix bad example of URI part-of to be bad, not good.") * 58f7a92ede378ed16fc6d18cdf2a4e56bc27c2e1. ("Add changelog entry for allowing URI in part-of.") * a4a7d98dcea609a527fc3ed2316b68a249e9192c. ("Use FutureOr in Completer.complete.") TBR=lrn@google.com Review-Url: https://codereview.chromium.org/2724853002 . --- CHANGELOG.md | 4 --- .../src/dart/analysis/library_analyzer.dart | 3 +- pkg/analyzer/lib/src/generated/engine.dart | 4 +-- pkg/analyzer/lib/src/generated/parser.dart | 2 +- .../lib/src/summary/summarize_ast.dart | 2 +- pkg/analyzer/lib/src/task/dart.dart | 3 +- pkg/analyzer/test/generated/parser_test.dart | 3 +- .../test/src/context/context_test.dart | 9 ++--- .../test/src/dart/analysis/driver_test.dart | 11 ++----- pkg/analyzer/test/src/task/dart_test.dart | 33 ++----------------- .../lib/src/diagnostics/messages.dart | 21 ------------ pkg/compiler/lib/src/elements/modelx.dart | 14 -------- .../lib/src/fasta/parser/parser.dart | 9 ++--- runtime/vm/parser.cc | 16 ++++----- sdk/lib/async/future.dart | 15 +++++---- sdk/lib/async/future_impl.dart | 6 ++-- tests/language/part_of_uri2_part.dart | 9 ----- tests/language/part_of_uri2_part2.dart | 9 ----- tests/language/part_of_uri2_test.dart | 15 --------- tests/language/part_of_uri_part.dart | 9 ----- tests/language/part_of_uri_part2.dart | 9 ----- tests/language/part_of_uri_test.dart | 14 -------- 22 files changed, 34 insertions(+), 186 deletions(-) delete mode 100644 tests/language/part_of_uri2_part.dart delete mode 100644 tests/language/part_of_uri2_part2.dart delete mode 100644 tests/language/part_of_uri2_test.dart delete mode 100644 tests/language/part_of_uri_part.dart delete mode 100644 tests/language/part_of_uri_part2.dart delete mode 100644 tests/language/part_of_uri_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 247d490df8d..105d22f2bc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,5 @@ ## 1.23.0 -### Language -* Allow using URI strings in `part of` declarations to refer to the - importing library. - ### Core library changes * `dart:core`: Added `Uri.isScheme` function to check the scheme of a URI. Example: `uri.isScheme("http")`. Ignores case when comparing. diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart index 71f1f2093d0..7ac3b30239b 100644 --- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart +++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart @@ -474,8 +474,7 @@ class LibraryAnalyzer { } } - if (hasPartDirective && libraryNameNode == null && - !_context.analysisOptions.enableUriInPartOf) { + if (hasPartDirective && libraryNameNode == null) { libraryErrorReporter.reportErrorForOffset( ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART, 0, 0); } diff --git a/pkg/analyzer/lib/src/generated/engine.dart b/pkg/analyzer/lib/src/generated/engine.dart index f96e9f674ec..97b72500d82 100644 --- a/pkg/analyzer/lib/src/generated/engine.dart +++ b/pkg/analyzer/lib/src/generated/engine.dart @@ -1422,7 +1422,7 @@ class AnalysisOptionsImpl implements AnalysisOptions { List _excludePatterns; @override - bool enableUriInPartOf = true; + bool enableUriInPartOf = false; @override bool generateImplicitErrors = true; @@ -1686,7 +1686,7 @@ class AnalysisOptionsImpl implements AnalysisOptions { enableStrictCallChecks = false; enableSuperMixins = false; enableTiming = false; - enableUriInPartOf = true; + enableUriInPartOf = false; _errorProcessors = null; _excludePatterns = null; finerGrainedInvalidation = false; diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart index 54e3e800651..e8bc7dd5d90 100644 --- a/pkg/analyzer/lib/src/generated/parser.dart +++ b/pkg/analyzer/lib/src/generated/parser.dart @@ -208,7 +208,7 @@ class Parser { * A flag indicating whether the parser is to allow URI's in part-of * directives. */ - bool _enableUriInPartOf = true; + bool _enableUriInPartOf = false; /** * A flag indicating whether parser is to parse function bodies. diff --git a/pkg/analyzer/lib/src/summary/summarize_ast.dart b/pkg/analyzer/lib/src/summary/summarize_ast.dart index ac2f3df3cf1..240fa8000ca 100644 --- a/pkg/analyzer/lib/src/summary/summarize_ast.dart +++ b/pkg/analyzer/lib/src/summary/summarize_ast.dart @@ -1368,7 +1368,7 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor { @override void visitPartOfDirective(PartOfDirective node) { - isCoreLibrary = node.libraryName?.name == 'dart.core'; + isCoreLibrary = node.libraryName.name == 'dart.core'; isPartOf = true; } diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart index daff329cb9e..a8cd2e6afbb 100644 --- a/pkg/analyzer/lib/src/task/dart.dart +++ b/pkg/analyzer/lib/src/task/dart.dart @@ -1626,8 +1626,7 @@ class BuildLibraryElementTask extends SourceBasedAnalysisTask { } } } - if (hasPartDirective && libraryNameNode == null && - !context.analysisOptions.enableUriInPartOf) { + if (hasPartDirective && libraryNameNode == null) { errors.add(new AnalysisError(librarySource, 0, 0, ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); } diff --git a/pkg/analyzer/test/generated/parser_test.dart b/pkg/analyzer/test/generated/parser_test.dart index e989e911258..ae8b9c2dcea 100644 --- a/pkg/analyzer/test/generated/parser_test.dart +++ b/pkg/analyzer/test/generated/parser_test.dart @@ -3419,8 +3419,7 @@ class Foo { void test_nonIdentifierLibraryName_partOf() { CompilationUnit unit = parseCompilationUnit( - "part of 3;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE, - ParserErrorCode.UNEXPECTED_TOKEN]); + "part of 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); expect(unit, isNotNull); } diff --git a/pkg/analyzer/test/src/context/context_test.dart b/pkg/analyzer/test/src/context/context_test.dart index 8374e0501d1..659538731be 100644 --- a/pkg/analyzer/test/src/context/context_test.dart +++ b/pkg/analyzer/test/src/context/context_test.dart @@ -766,13 +766,8 @@ library lib; Source partSource = addSource("/part.dart", "part of 'lib';"); context.parseCompilationUnit(librarySource); List errors = context.computeErrors(partSource); - if (context.analysisOptions.enableUriInPartOf) { - // TODO(28522) - // Should report that 'lib' isn't the correct URI. - } else { - expect(errors, isNotNull); - expect(errors.length > 0, isTrue); - } + expect(errors, isNotNull); + expect(errors.length > 0, isTrue); } void test_computeErrors_dart_some() { diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart index 53c4702f348..79e551fb2d4 100644 --- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart +++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart @@ -414,14 +414,9 @@ part of lib; AnalysisResult libResult = await driver.getResult(lib); List errors = libResult.errors; - if (libResult.unit.element.context.analysisOptions.enableUriInPartOf) { - // TODO(28522): Should cause an error for wrong library name. - expect(errors, hasLength(0)); - } else { - expect(errors, hasLength(1)); - expect(errors[0].errorCode, - ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART); - } + expect(errors, hasLength(1)); + expect(errors[0].errorCode, + ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART); } test_analyze_resolveDirectives_error_partOfDifferentLibrary_byName() async { diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart index f043d2a9047..d20b9b29d9e 100644 --- a/pkg/analyzer/test/src/task/dart_test.dart +++ b/pkg/analyzer/test/src/task/dart_test.dart @@ -870,37 +870,8 @@ part of my_lib; part of my_lib; ''' }); - if (context.analysisOptions.enableUriInPartOf) { - // TODO(28522) - // Should report that names are wrong. - } else { - _assertErrorsWithCodes( - [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]); - AnalysisError error = errorListener.errors[0]; - } - } - - test_perform_error_missingLibraryDirectiveWithPart_noCommon() { - _performBuildTask({ - '/lib.dart': ''' -part 'partA.dart'; -part 'partB.dart'; -''', - '/partA.dart': ''' -part of libA; - ''', - '/partB.dart': ''' -part of libB; -''' - }); - if (context.analysisOptions.enableUriInPartOf) { - // TODO(28522) - // Should report that names are wrong. - } else { - _assertErrorsWithCodes( - [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]); - AnalysisError error = errorListener.errors[0]; - } + _assertErrorsWithCodes( + [ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART]); } test_perform_error_partDoesNotExist() { diff --git a/pkg/compiler/lib/src/diagnostics/messages.dart b/pkg/compiler/lib/src/diagnostics/messages.dart index 45001eabb5f..751ffe73f3a 100644 --- a/pkg/compiler/lib/src/diagnostics/messages.dart +++ b/pkg/compiler/lib/src/diagnostics/messages.dart @@ -292,7 +292,6 @@ enum MessageKind { LIBRARY_NOT_FOUND, LIBRARY_NOT_SUPPORTED, LIBRARY_TAG_MUST_BE_FIRST, - LIBRARY_URI_MISMATCH, MAIN_HAS_PART_OF, MAIN_NOT_A_FUNCTION, MAIN_WITH_EXTRA_PARAMETER, @@ -2074,26 +2073,6 @@ main() {} """, 'part.dart': """ part of lib.bar; -""" - } - ]), - - MessageKind.LIBRARY_URI_MISMATCH: const MessageTemplate( - MessageKind.LIBRARY_URI_MISMATCH, - "Expected URI of library '#{libraryUri}'.", - howToFix: "Try changing the directive to 'part of " - "\"#{libraryUri}\";'.", - examples: const [ - const { - 'main.dart': """ -library lib.foo; - -part 'part.dart'; - -main() {} -""", - 'part.dart': """ -part of 'not-main.dart'; """ } ]), diff --git a/pkg/compiler/lib/src/elements/modelx.dart b/pkg/compiler/lib/src/elements/modelx.dart index d07cd7eebf6..bf589e1cbac 100644 --- a/pkg/compiler/lib/src/elements/modelx.dart +++ b/pkg/compiler/lib/src/elements/modelx.dart @@ -767,20 +767,6 @@ class CompilationUnitElementX extends ElementX } partTag = tag; LibraryName libraryTag = library.libraryTag; - - Expression libraryReference = tag.name; - if (libraryReference is LiteralString) { - // Name is a URI. Resolve and compare to library's URI. - String content = libraryReference.dartString.slowToString(); - Uri uri = this.script.readableUri.resolve(content); - Uri expectedUri = library.canonicalUri; - if (uri != expectedUri) { - // Consider finding a relative URI reference for the error message. - reporter.reportWarningMessage(tag.name, - MessageKind.LIBRARY_URI_MISMATCH, {'libraryUri': expectedUri}); - } - return; - } String actualName = tag.name.toString(); if (libraryTag != null) { String expectedName = libraryTag.name.toString(); diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart index 186f8965fcc..1eda2a6d2be 100644 --- a/pkg/front_end/lib/src/fasta/parser/parser.dart +++ b/pkg/front_end/lib/src/fasta/parser/parser.dart @@ -344,13 +344,8 @@ class Parser { assert(optional('part', token)); assert(optional('of', token.next)); Token partKeyword = token; - token = token.next.next; - if (token.isIdentifier()) { - token = parseQualified(token, IdentifierContext.partName, - IdentifierContext.partNameContinuation); - } else { - token = parseLiteralStringOrRecoverExpression(token); - } + token = parseQualified(token.next.next, IdentifierContext.partName, + IdentifierContext.partNameContinuation); Token semicolon = token; token = expect(';', token); listener.endPartOf(partKeyword, semicolon); diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc index 6a43faee2d6..f139e766cd6 100644 --- a/runtime/vm/parser.cc +++ b/runtime/vm/parser.cc @@ -6386,16 +6386,12 @@ void Parser::ParsePartHeader() { ReportError("'part of' expected"); } ConsumeToken(); - // The VM is not required to check that the library name or URI matches the - // name or URI of the current library, so we ignore them. - if (CurrentToken() == Token::kSTRING) { - ParseStringLiteral(false); - } else { - ExpectIdentifier("library name expected"); - while (CurrentToken() == Token::kPERIOD) { - ConsumeToken(); - ExpectIdentifier("malformed library name"); - } + // The VM is not required to check that the library name matches the + // name of the current library, so we ignore it. + ExpectIdentifier("library name expected"); + while (CurrentToken() == Token::kPERIOD) { + ConsumeToken(); + ExpectIdentifier("malformed library name"); } ExpectSemicolon(); } diff --git a/sdk/lib/async/future.dart b/sdk/lib/async/future.dart index 3e5dd58d50f..355cd4c7606 100644 --- a/sdk/lib/async/future.dart +++ b/sdk/lib/async/future.dart @@ -553,15 +553,17 @@ abstract class Future { * } * */ - // The `Function` below stands for one of two types: - // - (dynamic) -> FutureOr - // - (dynamic, StackTrace) -> FutureOr + // The `Function` below can stand for several types: + // - (dynamic) -> T + // - (dynamic, StackTrace) -> T + // - (dynamic) -> Future + // - (dynamic, StackTrace) -> Future // Given that there is a `test` function that is usually used to do an // `isCheck` we should also expect functions that take a specific argument. // Note: making `catchError` return a `Future` in non-strong mode could be // a breaking change. Future catchError(Function onError, - {bool test(Object error)}); + {bool test(Object error)}); /** * Register a function to be called when this future completes. @@ -783,7 +785,7 @@ abstract class Completer { * * All listeners on the future are informed about the value. */ - void complete([FutureOr value]); + void complete([value]); /** * Complete [future] with an error. @@ -825,4 +827,5 @@ void _completeWithErrorCallback(_Future result, error, stackTrace) { } /** Helper function that converts `null` to a [NullThrownError]. */ -Object _nonNullError(Object error) => error ?? new NullThrownError(); +Object _nonNullError(Object error) => + (error != null) ? error : new NullThrownError(); diff --git a/sdk/lib/async/future_impl.dart b/sdk/lib/async/future_impl.dart index 844646bbd53..eb13318ef7f 100644 --- a/sdk/lib/async/future_impl.dart +++ b/sdk/lib/async/future_impl.dart @@ -14,7 +14,7 @@ typedef _FutureAction(); abstract class _Completer implements Completer { final _Future future = new _Future(); - void complete([FutureOr value]); + void complete([value]); void completeError(Object error, [StackTrace stackTrace]) { error = _nonNullError(error); @@ -36,7 +36,7 @@ abstract class _Completer implements Completer { class _AsyncCompleter extends _Completer { - void complete([FutureOr value]) { + void complete([value]) { if (!future._mayComplete) throw new StateError("Future already completed"); future._asyncComplete(value); } @@ -47,7 +47,7 @@ class _AsyncCompleter extends _Completer { } class _SyncCompleter extends _Completer { - void complete([FutureOr value]) { + void complete([value]) { if (!future._mayComplete) throw new StateError("Future already completed"); future._complete(value); } diff --git a/tests/language/part_of_uri2_part.dart b/tests/language/part_of_uri2_part.dart deleted file mode 100644 index 22c889a5fd7..00000000000 --- a/tests/language/part_of_uri2_part.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// 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. - -part of "part_of_uri2_test.dart"; - -// Refer to declaration in library and other part. -const bar1 = "part1"; -const baz1 = "$foo${bar2}1"; diff --git a/tests/language/part_of_uri2_part2.dart b/tests/language/part_of_uri2_part2.dart deleted file mode 100644 index 0b049fbea66..00000000000 --- a/tests/language/part_of_uri2_part2.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// 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. - -part of part_of_uri2; - -// Refer to declaration in library and other part. -const bar2 = "part2"; -const baz2 = "$foo${bar1}2"; diff --git a/tests/language/part_of_uri2_test.dart b/tests/language/part_of_uri2_test.dart deleted file mode 100644 index 220c7449776..00000000000 --- a/tests/language/part_of_uri2_test.dart +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// 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. - -library part_of_uri2; - -part "part_of_uri2_part.dart"; // declares bar1, baz1, uses URI. -part "part_of_uri2_part2.dart"; // declares bar2, baz2, uses id. - -const foo = 'foo'; -const qux = "$baz1$baz2"; - -main() { - if (!identical(qux, "foopart21foopart12")) throw "Fail: $qux"; -} diff --git a/tests/language/part_of_uri_part.dart b/tests/language/part_of_uri_part.dart deleted file mode 100644 index 55edadf67a4..00000000000 --- a/tests/language/part_of_uri_part.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// 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. - -part of "part_of_uri_test.dart"; - -// Refer to declaration in library and other part. -const bar1 = "part1"; -const baz1 = "$foo${bar2}1"; diff --git a/tests/language/part_of_uri_part2.dart b/tests/language/part_of_uri_part2.dart deleted file mode 100644 index 5069b531381..00000000000 --- a/tests/language/part_of_uri_part2.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// 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. - -part of "part_of_uri_test.dart"; - -// Refer to declaration in library and other part. -const bar2 = "part2"; -const baz2 = "$foo${bar1}2"; diff --git a/tests/language/part_of_uri_test.dart b/tests/language/part_of_uri_test.dart deleted file mode 100644 index 4c313a0cccd..00000000000 --- a/tests/language/part_of_uri_test.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// 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. - -// No library declaration -part "part_of_uri_part.dart"; // declares bar1, baz1 -part "part_of_uri_part2.dart"; // declares bar2, baz2 - -const foo = 'foo'; -const qux = "$baz1$baz2"; - -main() { - if (!identical(qux, "foopart21foopart12")) throw "Fail: $qux"; -}