Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryaBelanger authored Feb 21, 2025
2 parents 5e07f1c + 52adad7 commit a75b9fb
Show file tree
Hide file tree
Showing 51 changed files with 1,539 additions and 1,150 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
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
8 changes: 4 additions & 4 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 @@ -35,7 +35,7 @@
"markdown-it-container": "^4.0.0",
"markdown-it-deflist": "^3.0.0",
"sass": "^1.85.0",
"shiki": "^2.4.2",
"tsx": "^4.19.2"
"shiki": "^3.0.0",
"tsx": "^4.19.3"
}
}
Loading

0 comments on commit a75b9fb

Please sign in to comment.