-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1087. More function tear-offs tests added
- Loading branch information
sgrekhov
committed
Jun 10, 2021
1 parent
4d770fd
commit dfab47f
Showing
5 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
LanguageFeatures/Constructor-tear-offs/dynamic_explicit_instantiation_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
/// @assertion We do not allow dynamic explicit instantiation. If an expression | ||
/// e has type dynamic (or Never), then e.foo<int> is a compile-time error for | ||
/// any name foo. (It'd be valid for a member of Object that was a generic | ||
/// function, but none of the Object members are generic functions). It's not | ||
/// possible to do implicit instantiation without knowing the member signature. | ||
/// | ||
/// @description Checks that dynamic explicit instantiation is a compile-time | ||
/// error | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
main() { | ||
dynamic d = new Object(); | ||
d.foo<int>; | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
29 changes: 29 additions & 0 deletions
29
LanguageFeatures/Constructor-tear-offs/dynamic_explicit_instantiation_A01_t02.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
/// @assertion We do not allow dynamic explicit instantiation. If an expression | ||
/// e has type dynamic (or Never), then e.foo<int> is a compile-time error for | ||
/// any name foo. (It'd be valid for a member of Object that was a generic | ||
/// function, but none of the Object members are generic functions). It's not | ||
/// possible to do implicit instantiation without knowing the member signature. | ||
/// | ||
/// @description Checks that dynamic explicit instantiation is a compile-time | ||
/// error | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
dynamic f(dynamic x) => x; | ||
|
||
class C { | ||
T instanceMethod<T>(T t) => t; | ||
} | ||
|
||
main() { | ||
C c = new C(); | ||
var v1 = f(c).instanceMethod<int>; | ||
// ^^^^^^^^^^^^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
36 changes: 36 additions & 0 deletions
36
LanguageFeatures/Constructor-tear-offs/function_tearoffs_A02_t12.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
/// @assertion These grammar changes allows type parameters without following | ||
/// parenthesized arguments in places where we previously did not allow them. | ||
/// For example, this means that <typeArguments> becomes a selector by itself, | ||
/// not just followed by arguments. | ||
// | ||
// It applies to instance methods as well as local, static and top-level | ||
// function declarations. For instance methods, it applies to references of the | ||
// form | ||
// | ||
// instanceMethod<int> (with implicit this), | ||
// object.instanceMethod<int> (including this) and super.instanceMethod<int>. | ||
/// | ||
/// @description Checks tear-off of generic static method | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
class C { | ||
static T staticMethod<T>(T t) => t; | ||
} | ||
|
||
main() { | ||
var x = C.staticMethod<int>; | ||
Expect.equals(42, x(42)); | ||
dynamic d1 = -42; | ||
Expect.isTrue(x(d1) is int); | ||
Expect.isFalse(x(d1) is double); // to check that returned type is not dynamic | ||
dynamic d2 = 3.14; | ||
Expect.throws(() {x(d2);}); | ||
} |
36 changes: 36 additions & 0 deletions
36
LanguageFeatures/Constructor-tear-offs/function_tearoffs_A02_t13.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
/// @assertion These grammar changes allows type parameters without following | ||
/// parenthesized arguments in places where we previously did not allow them. | ||
/// For example, this means that <typeArguments> becomes a selector by itself, | ||
/// not just followed by arguments. | ||
// | ||
// It applies to instance methods as well as local, static and top-level | ||
// function declarations. For instance methods, it applies to references of the | ||
// form | ||
// | ||
// instanceMethod<int> (with implicit this), | ||
// object.instanceMethod<int> (including this) and super.instanceMethod<int>. | ||
/// | ||
/// @description Checks tear-off of generic instance method | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
class C { | ||
static T staticMethod<T>(T t) => t; | ||
} | ||
|
||
main() { | ||
var x = C.staticMethod<int>; | ||
x(3.14); | ||
// ^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
x<double>(42); | ||
// ^^^^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
19 changes: 19 additions & 0 deletions
19
LanguageFeatures/Constructor-tear-offs/type_literal_static_type_A01_t01.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2021, 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. | ||
|
||
/// @assertion The static type of the instantiated type literal is Type | ||
/// | ||
/// @description Check that the static type of the instantiated type literal is | ||
/// Type | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
|
||
import "../../Utils/expect.dart"; | ||
|
||
main() { | ||
var intList = List<int>; | ||
Expect.isTrue(intList is Type); | ||
Expect.isFalse(intList is List<double>); // to check that intList is not dynamic | ||
} |