Skip to content

Commit

Permalink
Merge branch 'main' into guidelines-update-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniPiku authored Feb 24, 2025
2 parents 82c8635 + 31f8156 commit 902ea69
Show file tree
Hide file tree
Showing 60 changed files with 1,929 additions and 1,349 deletions.
18 changes: 18 additions & 0 deletions examples/misc/test/language_tour/generics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,21 @@ void main() {
}

class View {}

// #docregion f-bound
// ignore: one_member_abstracts
abstract interface class Comparable<T> {
int compareTo(T o);
}

int compareAndOffset<T extends Comparable<T>>(T t1, T t2) =>
t1.compareTo(t2) + 1;

class A implements Comparable<A> {
@override
int compareTo(A other) => /*...implementation...*/ 0;
}

var useIt = compareAndOffset(A(), A());

// #enddocregion f-bound
16 changes: 8 additions & 8 deletions examples/misc/test/library_tour/core_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,32 @@ void main() {
test('RegExp', () {
// #docregion regexp
// Here's a regular expression for one or more digits.
var numbers = RegExp(r'\d+');
var digitSequence = RegExp(r'\d+');

var allCharacters = 'llamas live fifteen to twenty years';
var lettersOnly = 'llamas live fifteen to twenty years';
var someDigits = 'llamas live 15 to 20 years';

// contains() can use a regular expression.
assert(!allCharacters.contains(numbers));
assert(someDigits.contains(numbers));
assert(!lettersOnly.contains(digitSequence));
assert(someDigits.contains(digitSequence));

// Replace every match with another string.
var exedOut = someDigits.replaceAll(numbers, 'XX');
var exedOut = someDigits.replaceAll(digitSequence, 'XX');
assert(exedOut == 'llamas live XX to XX years');
// #enddocregion regexp
});

test('match', () {
void testMatch() {
// #docregion match
var numbers = RegExp(r'\d+');
var digitSequence = RegExp(r'\d+');
var someDigits = 'llamas live 15 to 20 years';

// Check whether the reg exp has a match in a string.
assert(numbers.hasMatch(someDigits));
assert(digitSequence.hasMatch(someDigits));

// Loop through all matches.
for (final match in numbers.allMatches(someDigits)) {
for (final match in digitSequence.allMatches(someDigits)) {
print(match.group(0)); // 15, then 20
}
// #enddocregion match
Expand Down
10 changes: 10 additions & 0 deletions examples/type_system/lib/bounded/instantiate_to_bound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ void cannotRunThis() {
c.add(2);
// #enddocregion undefined-method
}

// #docregion inference-using-bounds-2
X max<X extends Comparable<X>>(X x1, X x2) => x1.compareTo(x2) > 0 ? x1 : x2;

void main() {
// Inferred as `max<num>(3, 7)` with the feature, fails without it.
max(3, 7);
}

// #enddocregion inference-using-bounds-2
21 changes: 21 additions & 0 deletions examples/type_system/lib/strong_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,24 @@ void _miscDeclAnalyzedButNotTested() {
// #enddocregion generic-type-assignment-implied-cast
}
}

// #docregion inference-using-bounds
class A<X extends A<X>> {}

class B extends A<B> {}

class C extends B {}

void f<X extends A<X>>(X x) {}

void main() {
f(B()); // OK.

// OK. Without using bounds, inference relying on best-effort approximations
// would fail after detecting that `C` is not a subtype of `A<C>`.
f(C());

f<B>(C()); // OK.
}

// #enddocregion inference-using-bounds
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"@types/hast": "^3.0.4",
"@types/markdown-it": "^14.1.2",
"@types/node": "^22.13.4",
"firebase-tools": "^13.31.1",
"firebase-tools": "^13.31.2",
"hast-util-from-html": "^2.0.3",
"hast-util-select": "^6.0.3",
"hast-util-select": "^6.0.4",
"hast-util-to-text": "^4.0.2",
"html-minifier-terser": "^7.2.0",
"js-yaml": "^4.1.0",
Expand All @@ -34,8 +34,8 @@
"markdown-it-attrs": "^4.3.1",
"markdown-it-container": "^4.0.0",
"markdown-it-deflist": "^3.0.0",
"sass": "^1.84.0",
"shiki": "^2.3.2",
"tsx": "^4.19.2"
"sass": "^1.85.0",
"shiki": "^3.0.0",
"tsx": "^4.19.3"
}
}
Loading

0 comments on commit 902ea69

Please sign in to comment.