-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Issues in the CFE related to pattern schemas in type inference #51587
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
Comments
Oh, this is tricky! ;-) I think I should comment on the terminology, just to make sure we're in sync. Also, I'm tempted to say something about a different topic, namely list patterns, and then return to records later on. A pattern in an irrefutable context is used to compute a type schema The resulting type after type inference is some type This means that we can have a context type schema where the type argument is void main() {
var [int i] = <dynamic>[1];
} In this example, the context type schema is With this in mind, the phrase
seems to refer to both the context type schema (which is obtained at first from the pattern), and the required type of the pattern (which is obtained by finalizing the pattern after we've found the static type of the initializing expression / right hand side). The problem is that it is dangerous to imply that the type argument is the same both times, so it's dangerous to use a terminology that seems to consider those two things to be the same: In the example above, the context type schema has type argument Returning to records, and the concrete example for this issue: In the example, the pattern is We don't have any type arguments for a record type, but the matched value type for each field pattern is used to perform the type check and finalization of each field (possibly adding coercions/demotions first, and then checking assignability). In this case we don't have anything which makes the distinction between the (early) type schema and the (late) required type as clear as it is with the list pattern, but we do get the same issues in some cases. For instance, we could have a record pattern where one field pattern is a list pattern, and that list pattern would then be treated in the same way as the list pattern at the top level which was considered in the example above. So we have to be equally strict on the terminology with record patterns. |
Thank you for the clarification, Erik! I updated the phrasing in my original message to use "the context type schema". |
The underlying issue appears to be fixed. |
I'm still seeing a compile time error in
In this code var (num b,) = (0,);
b as int;
b.isEven;
(b,) = (3.14,);
|
Thanks for noticing, @nshahan! There are a few interconnected issues, and I was too excited about fixing one of them and closed this issue prematurely. I reopened it and will work on making the CFE passing the test. |
As mentioned in #51585, the context type schema should be the shape, not the type in the record patterns.
Affected test: https://github.com/dart-lang/co19/blob/7b4f3e723211011878e185db6fa57fbafabd6bb7/LanguageFeatures/Patterns/type_inference_A26_t01.dart#L34-L37
The text was updated successfully, but these errors were encountered: