diff --git a/CHANGELOG.md b/CHANGELOG.md index 0726e842eb7..9000e3f4edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ ## 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 #### Pub diff --git a/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer.dart b/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer.dart index 1f0d8dca83d..6ef447f7362 100644 --- a/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer.dart +++ b/pkg/_fe_analyzer_shared/lib/src/type_inference/type_analyzer.dart @@ -387,8 +387,7 @@ mixin TypeAnalyzer< /// Computes the type schema for a cast pattern. /// /// Stack effect: none. - TypeSchema analyzeCastPatternSchema() => - operations.typeToSchema(operations.objectQuestionType); + TypeSchema analyzeCastPatternSchema() => operations.unknownType; /// Analyzes a constant pattern. [node] is the pattern itself, and /// [expression] is the constant expression. Depending on the client's diff --git a/pkg/_fe_analyzer_shared/test/type_inference/type_inference_test.dart b/pkg/_fe_analyzer_shared/test/type_inference/type_inference_test.dart index 4a5cfd334ae..4ce03b70929 100644 --- a/pkg/_fe_analyzer_shared/test/type_inference/type_inference_test.dart +++ b/pkg/_fe_analyzer_shared/test/type_inference/type_inference_test.dart @@ -1876,13 +1876,9 @@ main() { test('Type schema', () { var x = Var('x'); h.run([ - ifCase( - expr('num'), - x.pattern().as_('int'), - [], - ).checkIR('ifCase(expr(num), castPattern(varPattern(x, ' - 'matchedType: int, staticType: int), int, matchedType: num), ' - 'variables(x), true, block(), noop)'), + match(x.pattern().as_('int'), expr('num').checkSchema('?')).checkIR( + 'match(expr(num), castPattern(varPattern(x, ' + 'matchedType: int, staticType: int), int, matchedType: num))'), ]); }); diff --git a/pkg/analyzer/test/src/dart/resolution/cast_pattern_test.dart b/pkg/analyzer/test/src/dart/resolution/cast_pattern_test.dart index c3012eb4cab..2d571dab582 100644 --- a/pkg/analyzer/test/src/dart/resolution/cast_pattern_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/cast_pattern_test.dart @@ -102,7 +102,7 @@ PatternVariableDeclaration token: x staticElement: self::@function::f::@parameter::x staticType: dynamic - patternTypeSchema: Object? + patternTypeSchema: _ '''); } } diff --git a/tests/language/patterns/schema_test.dart b/tests/language/patterns/schema_test.dart index 79b490b97e4..25a191db03c 100644 --- a/tests/language/patterns/schema_test.dart +++ b/tests/language/patterns/schema_test.dart @@ -62,9 +62,7 @@ test() { // - Cast: The context type schema is `_`. { - // TODO(paulberry): uncomment this after - // https://github.com/dart-lang/sdk/issues/54640 is addressed. - // var [_ as Object] = [1]..expectStaticType>>(); + var [_ as Object] = [1]..expectStaticType>>(); } // - Parenthesized: The context type schema of the inner subpattern.