Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Follow up inference bounds fixes #6434

Merged
merged 20 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/type_system/lib/strong_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ void f<X extends A<X>>(X x) {}

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

// 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.
}

Expand Down
2 changes: 1 addition & 1 deletion src/content/language/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Specifying any non-`SomeBaseClass` type results in an error:
var foo = [!Foo<Object>!]();
```

### Self-referential type parameter restrictions (F-bounds)
### Self-referential type parameter restrictions (F-bounds) {:#f-bounds}

When using bounds to restrict parameter types, you can refer the bound
back to the type parameter itself. This creates a self-referential constraint,
Expand Down
10 changes: 7 additions & 3 deletions src/content/language/type-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,11 @@ void f<X extends A<X>>(X x) {}

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

// 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.
}
```
Expand Down Expand Up @@ -447,7 +450,8 @@ preserve the information that `mySet` is a `Set`.
For more information on the inference using bounds algorithm,
read the [design document][].

[F-bounded]: /language/generics/#self-referential-type-parameter-restrictions-f-bounds

[F-bounded]: /language/generics/#f-bounds
[design document]: {{site.repo.dart.lang}}/blob/main/accepted/future-releases/3009-inference-using-bounds/design-document.md#motivating-example

## Substituting types
Expand Down