diff --git a/examples/type_system/lib/strong_analysis.dart b/examples/type_system/lib/strong_analysis.dart index a6ca120e60..432e0bb8c4 100644 --- a/examples/type_system/lib/strong_analysis.dart +++ b/examples/type_system/lib/strong_analysis.dart @@ -168,8 +168,11 @@ void f>(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`. + + // OK. Without using bounds, inference relying on best-effort approximations + // would fail after detecting that `C` is not a subtype of `A`. + f(C()); + f(C()); // OK. } diff --git a/src/content/language/generics.md b/src/content/language/generics.md index 62ce12ef80..e98c6b8c1f 100644 --- a/src/content/language/generics.md +++ b/src/content/language/generics.md @@ -196,7 +196,7 @@ Specifying any non-`SomeBaseClass` type results in an error: var foo = [!Foo!](); ``` -### 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, diff --git a/src/content/language/type-system.md b/src/content/language/type-system.md index 52aed0c9a5..bebb18d2ba 100644 --- a/src/content/language/type-system.md +++ b/src/content/language/type-system.md @@ -400,8 +400,11 @@ void f>(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`. + + // OK. Without using bounds, inference relying on best-effort approximations + // would fail after detecting that `C` is not a subtype of `A`. + f(C()); + f(C()); // OK. } ``` @@ -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