mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:09:49 +00:00
Restore old nullability behavior of TypeParameterElement.type.
It doesn't work to make TypeParameterElement.type choose nullability/non-nullability based on the enclosing library, because for type parameters of synthetic function types, there is no enclosing library. Change-Id: Ic74cc639534e3c03f3c46e7eacfb5655ca74019a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102981 Auto-Submit: Paul Berry <paulberry@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
ce62987c9d
commit
f930d674ca
|
@ -9572,10 +9572,11 @@ class TypeParameterElementImpl extends ElementImpl
|
|||
}
|
||||
|
||||
TypeParameterType get type {
|
||||
return _type ??= new TypeParameterTypeImpl(this,
|
||||
nullabilitySuffix: library.isNonNullableByDefault
|
||||
? NullabilitySuffix.none
|
||||
: NullabilitySuffix.star);
|
||||
// Note: TypeParameterElement.type has nullability suffix `star` regardless
|
||||
// of whether it appears in a migrated library. This is because for type
|
||||
// parameters of synthetic function types, the ancestor chain is broken and
|
||||
// we can't find the enclosing library to tell whether it is migrated.
|
||||
return _type ??= new TypeParameterTypeImpl(this);
|
||||
}
|
||||
|
||||
void set type(TypeParameterType type) {
|
||||
|
|
|
@ -8,9 +8,11 @@ import 'package:analyzer/dart/analysis/declared_variables.dart';
|
|||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/file_system/file_system.dart';
|
||||
import 'package:analyzer/src/context/context.dart';
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/element/type.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
import 'package:analyzer/src/summary/idl.dart';
|
||||
import 'package:analyzer/src/summary/resynthesize.dart';
|
||||
|
@ -9438,6 +9440,40 @@ dynamic v;
|
|||
''');
|
||||
}
|
||||
|
||||
test_type_param_generic_function_type_nullability_legacy() async {
|
||||
featureSet = disableNnbd;
|
||||
var library = await checkLibrary('''
|
||||
T f<T>(T t) {}
|
||||
var g = f;
|
||||
''');
|
||||
checkElementText(library, '''
|
||||
T Function<T>(T) g;
|
||||
T f<T>(T t) {}
|
||||
''');
|
||||
var g = library.definingCompilationUnit.topLevelVariables[0];
|
||||
var t = (g.type as FunctionType).typeFormals[0];
|
||||
// TypeParameterElement.type has a nullability suffix of `star` regardless
|
||||
// of whether it appears in a migrated library.
|
||||
expect((t.type as TypeImpl).nullabilitySuffix, NullabilitySuffix.star);
|
||||
}
|
||||
|
||||
test_type_param_generic_function_type_nullability_migrated() async {
|
||||
featureSet = enableNnbd;
|
||||
var library = await checkLibrary('''
|
||||
T f<T>(T t) {}
|
||||
var g = f;
|
||||
''');
|
||||
checkElementText(library, '''
|
||||
T Function<T>(T) g;
|
||||
T f<T>(T t) {}
|
||||
''');
|
||||
var g = library.definingCompilationUnit.topLevelVariables[0];
|
||||
var t = (g.type as FunctionType).typeFormals[0];
|
||||
// TypeParameterElement.type has a nullability suffix of `star` regardless
|
||||
// of whether it appears in a migrated library.
|
||||
expect((t.type as TypeImpl).nullabilitySuffix, NullabilitySuffix.star);
|
||||
}
|
||||
|
||||
test_type_param_ref_nullability_none() async {
|
||||
featureSet = enableNnbd;
|
||||
var library = await checkLibrary('''
|
||||
|
|
Loading…
Reference in a new issue