Skip to content

Commit

Permalink
Follow up inference bounds fixes (#6434)
Browse files Browse the repository at this point in the history
Co-authored-by: Parker Lougheed <parlough@gmail.com>
Co-authored-by: Erik Ernst <eernst@google.com>
  • Loading branch information
3 people authored Feb 18, 2025
1 parent c2e9176 commit dd06d12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit dd06d12

Please sign in to comment.