mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Infer closure parameter types as Object instead of Null.
R=brianwilkerson@google.com, paulberry@google.com Bug: https://github.com/dart-lang/sdk/issues/31638 Change-Id: If739da50a1d7e21c6a1e18da18d1f85f788663da https://github.com/dart-lang/sdk/issues/31546 Reviewed-on: https://dart-review.googlesource.com/32669 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Paul Berry <paulberry@google.com>
This commit is contained in:
parent
72200eee24
commit
32e310d8c6
|
@ -128,6 +128,9 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
|
|||
// inferred a type in some fashion.
|
||||
if (p.hasImplicitType && (p.type == null || p.type.isDynamic)) {
|
||||
inferredType = ts.upperBoundForType(inferredType);
|
||||
if (inferredType.isDartCoreNull) {
|
||||
inferredType = _typeProvider.objectType;
|
||||
}
|
||||
if (!inferredType.isDynamic) {
|
||||
p.type = inferredType;
|
||||
inferred = true;
|
||||
|
|
46
pkg/analyzer/test/src/task/strong/dart2_inference_test.dart
Normal file
46
pkg/analyzer/test/src/task/strong/dart2_inference_test.dart
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../../generated/resolver_test_case.dart';
|
||||
import '../../../generated/test_support.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(Dart2InferenceTest);
|
||||
});
|
||||
}
|
||||
|
||||
/// Tests for Dart2 inference rules back-ported from FrontEnd.
|
||||
///
|
||||
/// https://github.com/dart-lang/sdk/issues/31638
|
||||
@reflectiveTest
|
||||
class Dart2InferenceTest extends ResolverTestCase {
|
||||
@override
|
||||
AnalysisOptions get defaultAnalysisOptions =>
|
||||
new AnalysisOptionsImpl()..strongMode = true;
|
||||
|
||||
@override
|
||||
bool get enableNewAnalysisDriver => true;
|
||||
|
||||
test_inferObject_whenDownwardNull() async {
|
||||
var code = r'''
|
||||
int f(void Function(Null) f2) {}
|
||||
void main() {
|
||||
f((x) {});
|
||||
}
|
||||
''';
|
||||
var source = addSource(code);
|
||||
var analysisResult = await computeAnalysisResult(source);
|
||||
var unit = analysisResult.unit;
|
||||
var xNode = EngineTestCase.findSimpleIdentifier(unit, code, 'x) {}');
|
||||
VariableElement xElement = xNode.staticElement;
|
||||
expect(xNode.staticType, typeProvider.objectType);
|
||||
expect(xElement.type, typeProvider.objectType);
|
||||
}
|
||||
}
|
|
@ -5,12 +5,14 @@
|
|||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'checker_test.dart' as checker_test;
|
||||
import 'dart2_inference_test.dart' as dart2_inference_test;
|
||||
import 'inferred_type_test.dart' as inferred_type_test;
|
||||
import 'non_null_checker_test.dart' as non_null_checker_test;
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
checker_test.main();
|
||||
dart2_inference_test.main();
|
||||
inferred_type_test.main();
|
||||
non_null_checker_test.main();
|
||||
}, name: 'strong');
|
||||
|
|
|
@ -24,7 +24,6 @@ built_in_identifier_prefix_test: CompileTimeError
|
|||
built_in_identifier_type_annotation_test/22: MissingCompileTimeError # Issue 28816
|
||||
cascaded_forwarding_stubs_generic_test: RuntimeError
|
||||
cascaded_forwarding_stubs_test: CompileTimeError
|
||||
closure_param_null_to_object_test: RuntimeError
|
||||
combiner_type_lookup_indexed_test: CompileTimeError # Issue #31484
|
||||
combiner_type_lookup_instance_test: CompileTimeError # Issue #31484
|
||||
combiner_type_lookup_static_test: CompileTimeError # Issue #31484
|
||||
|
|
Loading…
Reference in a new issue