-
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. Syntax tests for non-trivial function object computation added
- Loading branch information
sgrekhov
committed
Sep 14, 2021
1 parent
21e8932
commit 13a6675
Showing
6 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
LanguageFeatures/Constructor-tear-offs/syntax_A03_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,37 @@ | ||
// 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 now allow instantiating function objects, and therefore we do | ||
/// not need to restrict callable objects either. | ||
/// | ||
/// The variable initialization above will, after type inference, be | ||
/// | ||
/// int Function(int) intId = Id().call<int>; | ||
/// Also, we allow explicitly instantiating a callable object: | ||
/// | ||
/// var intId = Id()<int>; | ||
/// is also type-inferred to the same initialization. | ||
/// | ||
/// @description Checks callable object invocation with '!' | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
import "../../Utils/expect.dart"; | ||
|
||
T foo1<T>(T value) => value; | ||
|
||
main() { | ||
int Function(int)? f1; | ||
if (2 > 1) { | ||
f1 = foo1.call<int>; | ||
} | ||
Expect.equals(42, f1!(42)); | ||
|
||
T foo2<T>(T value) => value; | ||
int Function(int)? f2; | ||
if (2 > 1) { | ||
f2 = foo2.call<int>; | ||
} | ||
Expect.equals(42, f2!(42)); | ||
} |
34 changes: 34 additions & 0 deletions
34
LanguageFeatures/Constructor-tear-offs/syntax_A04_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,34 @@ | ||
// 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 This feature introduces syntax to explicitly instantiate a | ||
/// generic function object or tear-off and a type literal for a generic type. | ||
/// The former for consistency with constructor tear-offs, the latter to | ||
/// introduce in-line types without needing a typedef, like we did for in-line | ||
/// function types originally. We introduce both now because they share the same | ||
/// grammar productions. | ||
/// | ||
/// Example: | ||
/// | ||
/// T id<T>(T value) => value; | ||
/// var idInt = id<int>; // Explicitly instantiated tear-off, saves on function types. | ||
/// // and | ||
/// Type intList = List<int>; // In-line instantiated type literal. | ||
/// | ||
/// @description Checks non-trivial computation to obtain function object for | ||
/// explicit generic instantiation | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
import "../../Utils/expect.dart"; | ||
|
||
T foo1<T>(T value) => value; | ||
|
||
main() { | ||
var funcVar1 = foo1; | ||
var funcVarInt1 = foo1<int>; | ||
Expect.equals(42, funcVarInt1(42)); | ||
var funcVarInt2 = ( 2 > 1 ? funcVar1 : funcVar1)<int>; | ||
Expect.equals(42, funcVarInt2(42)); | ||
} |
35 changes: 35 additions & 0 deletions
35
LanguageFeatures/Constructor-tear-offs/syntax_A04_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,35 @@ | ||
// 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 This feature introduces syntax to explicitly instantiate a | ||
/// generic function object or tear-off and a type literal for a generic type. | ||
/// The former for consistency with constructor tear-offs, the latter to | ||
/// introduce in-line types without needing a typedef, like we did for in-line | ||
/// function types originally. We introduce both now because they share the same | ||
/// grammar productions. | ||
/// | ||
/// Example: | ||
/// | ||
/// T id<T>(T value) => value; | ||
/// var idInt = id<int>; // Explicitly instantiated tear-off, saves on function types. | ||
/// // and | ||
/// Type intList = List<int>; // In-line instantiated type literal. | ||
/// | ||
/// @description Checks non-trivial computation to obtain function object for | ||
/// explicit generic instantiation | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
import "../../Utils/expect.dart"; | ||
|
||
T foo<T>(T value) => value; | ||
typedef T Foo<T>(T t); | ||
|
||
Foo<T> getFoo1<T>() => foo<T>; | ||
T Function<T>(T) getFoo2() => foo; | ||
|
||
main() { | ||
Expect.equals(42, getFoo1<int>()(42)); | ||
Expect.equals(42, getFoo2()<int>(42)); | ||
} |
33 changes: 33 additions & 0 deletions
33
LanguageFeatures/Constructor-tear-offs/syntax_A04_t03.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,33 @@ | ||
// 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 This feature introduces syntax to explicitly instantiate a | ||
/// generic function object or tear-off and a type literal for a generic type. | ||
/// The former for consistency with constructor tear-offs, the latter to | ||
/// introduce in-line types without needing a typedef, like we did for in-line | ||
/// function types originally. We introduce both now because they share the same | ||
/// grammar productions. | ||
/// | ||
/// Example: | ||
/// | ||
/// T id<T>(T value) => value; | ||
/// var idInt = id<int>; // Explicitly instantiated tear-off, saves on function types. | ||
/// // and | ||
/// Type intList = List<int>; // In-line instantiated type literal. | ||
/// | ||
/// @description Checks non-trivial computation to obtain function object for | ||
/// explicit generic instantiation | ||
/// @author sgrekhov@unipro.ru | ||
// SharedOptions=--enable-experiment=constructor-tearoffs | ||
import "../../Utils/expect.dart"; | ||
|
||
class C<Y> { | ||
X foo<X>(X x) => x; | ||
T Function<T>(T) call<Z>(String s) => foo; | ||
} | ||
|
||
main() { | ||
Expect.equals(42, C<Object>()<int>("Lily was here")<int>(42)); | ||
} |