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

Add proposal for partial type inference #7582

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
df50582
Partial type inference
TomatorCZ Oct 7, 2023
6e3c0cb
Update partial-type-inference.md
jcouv Nov 2, 2023
afc1eca
Remove header template
jcouv Nov 2, 2023
44bf3a2
fix typo
TomatorCZ Nov 4, 2023
54ee1c4
fix typo
TomatorCZ Nov 4, 2023
469a112
change wording
TomatorCZ Nov 5, 2023
33b71f0
change wording and fix typo
TomatorCZ Nov 5, 2023
5e59e96
delete unnecessary part of example
TomatorCZ Nov 5, 2023
b6081e3
change formulation of type_name meaning
TomatorCZ Nov 5, 2023
6039b9f
change grammar of type argument section
TomatorCZ Nov 5, 2023
ea87f2f
make type inference using initializers and types with floating arity …
TomatorCZ Nov 5, 2023
8c7eadb
typo
TomatorCZ Feb 3, 2024
ebe9eaf
typo
TomatorCZ Feb 3, 2024
47524ae
type
TomatorCZ Feb 3, 2024
8db3728
Merge branch 'dotnet:main' into main
TomatorCZ Feb 3, 2024
9daa672
typo
TomatorCZ Feb 3, 2024
e973d80
shrink comments in code examples
TomatorCZ Feb 3, 2024
4485ab9
add possible resolutions of _ used as a typename
TomatorCZ Feb 3, 2024
524a491
typo
TomatorCZ Feb 3, 2024
9dfa24f
make changes regarding type inference more clear
TomatorCZ Feb 3, 2024
7aa277e
remove block quotes
TomatorCZ Feb 3, 2024
e9b827b
fix code example
TomatorCZ Mar 13, 2024
87cc926
Update proposals/partial-type-inference.md
TomatorCZ Mar 13, 2024
98d835e
move nullability to type arguments section
TomatorCZ Mar 13, 2024
be609af
Add proposal containing just
Apr 16, 2024
2537f53
typo
Apr 16, 2024
254b137
typo
Apr 16, 2024
4f01563
adjust object creation expression binding
Apr 16, 2024
fe31185
typo
Apr 16, 2024
e20b17a
remove outdated explanation
Apr 16, 2024
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
8 changes: 4 additions & 4 deletions proposals/partial-type-inference-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ The initial set of candidate methods for is changed by adding new condition.
- If `F` is generic and `M` has no type argument list, `F` is a candidate when:
- Type inference (§12.6.3) succeeds, inferring a list of type arguments for the call, and
- Once the inferred type arguments are substituted for the corresponding method type parameters, all constructed types in the parameter list of `F` satisfy their constraints ([§8.4.5](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/types.md#845-satisfying-constraints)), and the parameter list of `F` is applicable with respect to `A` (§12.6.4.2)
- **If `F` is generic and `M` has a type argument list containing at least one *inferred_type* or *partial_inferred_type*, `F` is a candidate when:**
- **If `F` is generic and `M` is *partial_inferred*, `F` is a candidate when:**
- **Method type inference (See the [Type Inference] section) succeeds, inferring the type arguments list for the call, and**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was Type Inference meant to be a link here?

Copy link
Author

@TomatorCZ TomatorCZ Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- **Once the inferred type arguments are substituted for the corresponding method type parameters, all constructed types in the parameter list of `F` satisfy their constraints ([§8.4.5](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/types.md#845-satisfying-constraints)), and the parameter list of `F` is applicable with respect to `A` ([§12.6.4.2](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/expressions.md#12642-applicable-function-member))**
- If `F` is generic and `M` includes a type argument list, `F` is a candidate when:
Expand All @@ -175,16 +175,16 @@ The binding-time processing of an *object_creation_expression* of the form new `

- If `T` is a *value_type* and `A` is not present:
- **The *object_creation_expression* is a default constructor invocation.**
- **If the type is *partially_inferred*, Constructor type inference (See the [Type Inference] section) of the default constructor occurs to determine closed type. If it succeeded, construct the type using the inferred type arguments. If it failed the binding-time error occurs.**
- **If the type is *partial_inferred*, Constructor type inference (See the [Type Inference] section) of the default constructor occurs to determine closed type. If it succeeded, construct the type using the inferred type arguments. If it failed the binding-time error occurs.**
- **If the type inference above succeeded or the type is not inferred, the result of the *object_creation_expression* is a value of (constructed) type `T`, namely the default value for `T` as defined in [§8.3.3](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/types.md#833-default-constructors).**
- Otherwise, if `T` is a *type_parameter* and `A` is not present:
- If no value type constraint or constructor constraint (§15.2.5) has been specified for `T`, a binding-time error occurs.
- The result of the *object_creation_expression* is a value of the run-time type that the type parameter has been bound to, namely the result of invoking the default constructor of that type. The run-time type may be a reference type or a value type.
- Otherwise, if `T` is a *class_type* or a *struct_type*:
- If `T` is an abstract or static *class_type*, a compile-time error occurs.
- **The instance constructor to invoke is determined using the overload resolution rules of [§12.6.4](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/expressions.md#1264-overload-resolution). The set of candidate instance constructors is determined as follows:**
- **`T` is not inferrred (*partially_inferred*), the constructor is accessible in `T`, and is applicable with respect to `A` ([§12.6.4.2](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/expressions.md#12642-applicable-function-member)).**
- **If `T` is *partially_constructed* and the constructor is accessible in `T`, partial constructor type inference of the constructor is performed. Once the type arguments are inferred and substituted for the corresponding type parameters, all constructed types in the parameter list of the constructor satisfy their constraints, and the parameter list of the constructor is applicable with respect to `A` ([§12.6.4.2](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/expressions.md#12642-applicable-function-member)).**
- **`T` is not inferrred (*partial_inferred*), the constructor is accessible in `T`, and is applicable with respect to `A` ([§12.6.4.2](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/expressions.md#12642-applicable-function-member)).**
- **If `T` is *partial_inferred* and the constructor is accessible in `T`, constructor type inference of the constructor is performed. Once the type arguments are inferred and substituted for the corresponding type parameters, all constructed types in the parameter list of the constructor satisfy their constraints, and the parameter list of the constructor is applicable with respect to `A` ([§12.6.4.2](https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/expressions.md#12642-applicable-function-member)).**
- A binding-time error occurs when:
- The set of candidate instance constructors is empty, or if a single best instance constructor cannot be identified.
- The result of the *object_creation_expression* is a value of type `T`, namely the value produced by invoking the instance constructor determined in the two steps above.
Expand Down