Skip to content

Commit

Permalink
[CFE] [Language versioning] Issue error on multiple 'dart=' entries
Browse files Browse the repository at this point in the history
Issue error when the .packages file specifies more than on 'dart=' entry.
Also add another test of the library and part mismatch being an error.

Change-Id: I0a894e6ef86eb9f976b9fbdce67f0c9adb03be9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112881
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
jensjoha authored and commit-bot@chromium.org committed Aug 13, 2019
1 parent e47f354 commit b9217ef
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/front_end/lib/src/fasta/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,19 @@ abstract class Loader {
int packageSpecifiedLanguageVersionMinor;
if (packageFragment != null) {
List<String> properties = packageFragment.split("&");
int foundEntries = 0;
for (int i = 0; i < properties.length; ++i) {
String property = properties[i];
if (property.startsWith("dart=")) {
if (++foundEntries > 1) {
// Force error to be issued if more than one "dart=" entry.
// (The error will be issued in library.setLanguageVersion below
// when giving it `null` version numbers.)
packageSpecifiedLanguageVersionMajor = null;
packageSpecifiedLanguageVersionMinor = null;
break;
}

hasPackageSpecifiedLanguageVersion = true;
String langaugeVersionString = property.substring(5);

Expand All @@ -140,7 +150,6 @@ abstract class Loader {
packageSpecifiedLanguageVersionMinor =
int.tryParse(dotSeparatedParts[1]);
}
break;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/front_end/lib/src/testing/id_testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ Future runTests(Directory dataDir,
int testCount = 0;
for (FileSystemEntity entity in entities) {
String name = entity.uri.pathSegments.last;
if (entity is Directory) {
name = entity.uri.pathSegments[entity.uri.pathSegments.length - 2];
}
if (args.isNotEmpty && !args.contains(name) && !continued) continue;
if (shouldContinue) continued = true;
testCount++;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo:lib/#dart=2.5&dart=arglebargle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*error: LanguageVersionInvalidInDotPackages*/
// Copyright (c) 2019, 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: languageVersion=2.8*/

import 'foo2.dart';

foo() {
print("Hello from foo!");
foo2();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*error: LanguageVersionInvalidInDotPackages*/
// Copyright (c) 2019, 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.

// @dart = 2.4

/*library: languageVersion=2.4*/

foo2() {
print("Hello from foo2!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2019, 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.

// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.

// @dart = 2.4

import 'package:foo/foo.dart';

/*library: languageVersion=2.4*/

main() {
foo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2019, 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.

# Analyzer workaround, see https://github.com/dart-lang/sdk/issues/37513
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo:lib/#dart=2.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) 2019, 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.

// The library and its part is both technically at language version 2.5,
// but one is explicitly set, the other is not. That's an error.

part /*error: LanguageVersionMismatchInPart*/ 'part.dart';

/*library: languageVersion=2.5*/

foo() {
/*error: MethodNotFound*/ bar();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2019, 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.

// @dart = 2.5

part of 'foo.dart';

bar() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2019, 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.

// Set version of this file (not technically in package) explicitly to test as
// much as possibly separately.

// @dart = 2.4

import 'package:foo/foo.dart';

/*library: languageVersion=2.4*/

main() {
main();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2019, 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.

# Analyzer workaround, see https://github.com/dart-lang/sdk/issues/37513

0 comments on commit b9217ef

Please sign in to comment.