mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 16:44:59 +00:00
Fix pattern context type schema for cast patterns.
According to the patterns spec, the pattern context type schema for a cast pattern should be `_`. What was actually implemented was `Object?`. This is unlikely to make a difference in practice, since (a) cast patterns are unlikely to be used in circumstances where the pattern context type schema makes a difference, and (b) it takes some effort to come up with expressions whose type inference behavior is differenc between a schema of `Object?` and a schema of `_`. Change-Id: I695752c8c163621a34faaa8d62b2b076c8152eb0 Bug: https://github.com/dart-lang/sdk/issues/54640 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346383 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
This commit is contained in:
parent
2958754ed8
commit
3636c8a08b
|
@ -1,5 +1,14 @@
|
||||||
## 3.4.0
|
## 3.4.0
|
||||||
|
|
||||||
|
### Language
|
||||||
|
|
||||||
|
- **Breaking Change** [#54640][]: The pattern context type schema for
|
||||||
|
cast patterns has been changed from `Object?` to `_` (the unknown
|
||||||
|
type), to align with the specification. This change is not expected
|
||||||
|
to make any difference in practice.
|
||||||
|
|
||||||
|
[#54640]: https://github.com/dart-lang/sdk/issues/54640
|
||||||
|
|
||||||
### Tools
|
### Tools
|
||||||
|
|
||||||
#### Pub
|
#### Pub
|
||||||
|
|
|
@ -387,8 +387,7 @@ mixin TypeAnalyzer<
|
||||||
/// Computes the type schema for a cast pattern.
|
/// Computes the type schema for a cast pattern.
|
||||||
///
|
///
|
||||||
/// Stack effect: none.
|
/// Stack effect: none.
|
||||||
TypeSchema analyzeCastPatternSchema() =>
|
TypeSchema analyzeCastPatternSchema() => operations.unknownType;
|
||||||
operations.typeToSchema(operations.objectQuestionType);
|
|
||||||
|
|
||||||
/// Analyzes a constant pattern. [node] is the pattern itself, and
|
/// Analyzes a constant pattern. [node] is the pattern itself, and
|
||||||
/// [expression] is the constant expression. Depending on the client's
|
/// [expression] is the constant expression. Depending on the client's
|
||||||
|
|
|
@ -1876,13 +1876,9 @@ main() {
|
||||||
test('Type schema', () {
|
test('Type schema', () {
|
||||||
var x = Var('x');
|
var x = Var('x');
|
||||||
h.run([
|
h.run([
|
||||||
ifCase(
|
match(x.pattern().as_('int'), expr('num').checkSchema('?')).checkIR(
|
||||||
expr('num'),
|
'match(expr(num), castPattern(varPattern(x, '
|
||||||
x.pattern().as_('int'),
|
'matchedType: int, staticType: int), int, matchedType: num))'),
|
||||||
[],
|
|
||||||
).checkIR('ifCase(expr(num), castPattern(varPattern(x, '
|
|
||||||
'matchedType: int, staticType: int), int, matchedType: num), '
|
|
||||||
'variables(x), true, block(), noop)'),
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ PatternVariableDeclaration
|
||||||
token: x
|
token: x
|
||||||
staticElement: self::@function::f::@parameter::x
|
staticElement: self::@function::f::@parameter::x
|
||||||
staticType: dynamic
|
staticType: dynamic
|
||||||
patternTypeSchema: Object?
|
patternTypeSchema: _
|
||||||
''');
|
''');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,7 @@ test() {
|
||||||
|
|
||||||
// - Cast: The context type schema is `_`.
|
// - Cast: The context type schema is `_`.
|
||||||
{
|
{
|
||||||
// TODO(paulberry): uncomment this after
|
var [_ as Object] = [1]..expectStaticType<Exactly<List<int>>>();
|
||||||
// https://github.com/dart-lang/sdk/issues/54640 is addressed.
|
|
||||||
// var [_ as Object] = [1]..expectStaticType<Exactly<List<int>>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - Parenthesized: The context type schema of the inner subpattern.
|
// - Parenthesized: The context type schema of the inner subpattern.
|
||||||
|
|
Loading…
Reference in a new issue