Skip to content

Commit b9217ef

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[CFE] [Language versioning] Issue error on multiple 'dart=' entries
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>
1 parent e47f354 commit b9217ef

File tree

12 files changed

+105
-1
lines changed

12 files changed

+105
-1
lines changed

pkg/front_end/lib/src/fasta/loader.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,19 @@ abstract class Loader {
126126
int packageSpecifiedLanguageVersionMinor;
127127
if (packageFragment != null) {
128128
List<String> properties = packageFragment.split("&");
129+
int foundEntries = 0;
129130
for (int i = 0; i < properties.length; ++i) {
130131
String property = properties[i];
131132
if (property.startsWith("dart=")) {
133+
if (++foundEntries > 1) {
134+
// Force error to be issued if more than one "dart=" entry.
135+
// (The error will be issued in library.setLanguageVersion below
136+
// when giving it `null` version numbers.)
137+
packageSpecifiedLanguageVersionMajor = null;
138+
packageSpecifiedLanguageVersionMinor = null;
139+
break;
140+
}
141+
132142
hasPackageSpecifiedLanguageVersion = true;
133143
String langaugeVersionString = property.substring(5);
134144

@@ -140,7 +150,6 @@ abstract class Loader {
140150
packageSpecifiedLanguageVersionMinor =
141151
int.tryParse(dotSeparatedParts[1]);
142152
}
143-
break;
144153
}
145154
}
146155
}

pkg/front_end/lib/src/testing/id_testing.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ Future runTests(Directory dataDir,
635635
int testCount = 0;
636636
for (FileSystemEntity entity in entities) {
637637
String name = entity.uri.pathSegments.last;
638+
if (entity is Directory) {
639+
name = entity.uri.pathSegments[entity.uri.pathSegments.length - 2];
640+
}
638641
if (args.isNotEmpty && !args.contains(name) && !continued) continue;
639642
if (shouldContinue) continued = true;
640643
testCount++;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo:lib/#dart=2.5&dart=arglebargle
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*error: LanguageVersionInvalidInDotPackages*/
2+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
3+
// for details. All rights reserved. Use of this source code is governed by a
4+
// BSD-style license that can be found in the LICENSE file.
5+
6+
/*library: languageVersion=2.8*/
7+
8+
import 'foo2.dart';
9+
10+
foo() {
11+
print("Hello from foo!");
12+
foo2();
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*error: LanguageVersionInvalidInDotPackages*/
2+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
3+
// for details. All rights reserved. Use of this source code is governed by a
4+
// BSD-style license that can be found in the LICENSE file.
5+
6+
// @dart = 2.4
7+
8+
/*library: languageVersion=2.4*/
9+
10+
foo2() {
11+
print("Hello from foo2!");
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Set version of this file (not technically in package) explicitly to test as
6+
// much as possibly separately.
7+
8+
// @dart = 2.4
9+
10+
import 'package:foo/foo.dart';
11+
12+
/*library: languageVersion=2.4*/
13+
14+
main() {
15+
foo();
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
# Analyzer workaround, see https://github.com/dart-lang/sdk/issues/37513
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo:lib/#dart=2.5
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// The library and its part is both technically at language version 2.5,
6+
// but one is explicitly set, the other is not. That's an error.
7+
8+
part /*error: LanguageVersionMismatchInPart*/ 'part.dart';
9+
10+
/*library: languageVersion=2.5*/
11+
12+
foo() {
13+
/*error: MethodNotFound*/ bar();
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// @dart = 2.5
6+
7+
part of 'foo.dart';
8+
9+
bar() {}

0 commit comments

Comments
 (0)