Skip to content

Commit 8ca18f1

Browse files
leafpetersencommit-bot@chromium.org
authored andcommitted
Extension method prefixed import tests.
Adds tests for the change to make extension members accessible even for prefixed imports. Also tests that it is an error to import a library with extensions as deferred without hiding the extensions. Change-Id: I3a81c560694d34c8adbb4cc86ca9e6b8a129ae56 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124589 Commit-Queue: Leaf Petersen <leafp@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com>
1 parent 750a83b commit 8ca18f1

26 files changed

+314
-64
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
// An extension conflicting with the one from "on_object.dart";
6+
extension AlsoOnObject on Object {
7+
String get onObject => "also object";
8+
}

tests/language_2/extension_methods/helpers/class_no_shadow.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// SharedOptions=--enable-experiment=extension-methods
6-
75
import "package:expect/expect.dart";
86

97
const String instanceValue = "1";

tests/language_2/extension_methods/helpers/class_shadow.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// SharedOptions=--enable-experiment=extension-methods
6-
75
import "package:expect/expect.dart";
86

97
import "class_no_shadow.dart";

tests/language_2/extension_methods/helpers/extension_all.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// SharedOptions=--enable-experiment=extension-methods
6-
75
import "package:expect/expect.dart";
86
import "class_no_shadow.dart";
97

tests/language_2/extension_methods/helpers/extension_global_instance.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// SharedOptions=--enable-experiment=extension-methods
6-
75
import "package:expect/expect.dart";
86
import "class_no_shadow.dart";
97

tests/language_2/extension_methods/helpers/extension_only.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// SharedOptions=--enable-experiment=extension-methods
6-
75
import "package:expect/expect.dart";
86
import "class_no_shadow.dart";
97

tests/language_2/extension_methods/helpers/global_scope.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// SharedOptions=--enable-experiment=extension-methods
6-
75
import "package:expect/expect.dart";
86

97
const int globalValue = 0;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
extension OnInt on int {
6+
String get onObject => "int";
7+
String get onInt => "int";
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
extension OnObject on Object {
6+
String get onObject => "object";
7+
}
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+
import "package:expect/expect.dart";
6+
7+
import "helpers/on_object.dart";
8+
import "helpers/on_object.dart" deferred as p1 hide OnObject;
9+
10+
// Allow explicit and implicit access to non-deferred import extensions.
11+
12+
void main() async {
13+
Object o = 1;
14+
Expect.equals("object", OnObject(o).onObject);
15+
Expect.equals("object", o.onObject);
16+
}

0 commit comments

Comments
 (0)