-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smoke tests for function as type parameter and triple-shift (#2603)
* beginning * first test * test * begin extracting annotation * dartfmt, comment * Update skip * Rebuild renderers * Beginning feature refactor * Getting there * obliterate strings * Final cleanups * Bypass @Native crashing us in flutter * Restrict ast import * Expand feature rendering out and get span classes fixed in parameters * dartfmt * Very basic tests * review comments * Add tests for triple-shift * dartfmt * Add skip outside 2.13
- Loading branch information
1 parent
342d2d7
commit 31ec93e
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ analyzer: | |
enable-experiment: | ||
- non-nullable | ||
- nonfunction-type-aliases | ||
- triple-shift | ||
- generic-metadata |
48 changes: 48 additions & 0 deletions
48
testing/test_package_experiments/lib/generic_functions_as_type_args.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,48 @@ | ||
// 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. | ||
|
||
/// Tests for verifying generic functions as type arguments. | ||
library generic_function_type_args; | ||
|
||
late List<T Function<T>(T)> idFunctions; | ||
late S Function<S extends T Function<T>(T)>(S) ff; | ||
|
||
typedef F = T Function<T>(T); | ||
|
||
class C<T> { | ||
final T value; | ||
const C(this.value); | ||
} | ||
|
||
T f<T>(T value) => value; | ||
|
||
extension E<T> on T { | ||
T get extensionValue => this; | ||
} | ||
|
||
// A generic function type can be a type parameter bound. | ||
|
||
// For a type alias: | ||
typedef FB<T extends F> = S Function<S extends T>(S); | ||
|
||
// For a class: | ||
class CB<T extends FB<F>> { | ||
final T function; | ||
const CB(this.function); | ||
} | ||
|
||
// For a function: | ||
T fb<T extends F>(T value) => value; | ||
|
||
extension EB<T extends F> on T { | ||
T get boundExtensionValue => this; | ||
|
||
// Any function type has a `call` of its own type? | ||
T get boundCall => this.call; | ||
} | ||
|
||
// Can be used as arguments to metadata too. | ||
@C<F>(f) | ||
@CB<FB<F>>(fb) | ||
void main() {} |
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,42 @@ | ||
// 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. | ||
|
||
/// Tests for verifying triple_shift operator, borrowed from the SDK. | ||
library triple_shift; | ||
|
||
class C { | ||
static int ctr = 0; | ||
|
||
/// Check that constants using a triple shift operator appear correctly. | ||
static const int constantTripleShifted = 3>>>5; | ||
final Object? _text; | ||
C([Object? text]) : _text = text ?? "${++ctr}"; | ||
|
||
// It's possible to declare a `>>>` operator. | ||
C operator >>>(arg) => C("(${++ctr}:$_text>>>$arg)"); | ||
|
||
// + binds more strongly than `>>`, `>>>` and `<<`. | ||
C operator +(arg) => C("(${++ctr}:$_text+$arg)"); | ||
// Both `>>` and `<<` binds exactly as strongly as `>>>`. | ||
C operator >>(arg) => C("(${++ctr}:$_text>>$arg)"); | ||
C operator <<(arg) => C("(${++ctr}:$_text<<$arg)"); | ||
// & binds less strongly than `>>`, `>>>` and `<<`. | ||
C operator &(arg) => C("(${++ctr}:$_text&$arg)"); | ||
|
||
String toString() => "${_text}"; | ||
} | ||
|
||
class _D extends C {} | ||
|
||
class E extends _D {} | ||
|
||
class F extends E { | ||
@override | ||
F operator >>>(arg) => F(); | ||
} | ||
|
||
// Valid in extensions too. | ||
extension ShiftIt<T> on T { | ||
List<T> operator >>>(int count) => List<T>.filled(count, this); | ||
} |