Reland "Implement the type Never"

This reverts commit 78e50a5f9b.

Change-Id: I2ec4cdcfda4a6d199308a3b25a2ed0792e9d9a26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101621
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Brian Wilkerson 2019-05-08 13:26:45 +00:00 committed by commit-bot@chromium.org
parent 9203ad5e89
commit f80f0bfcfd
29 changed files with 298 additions and 61 deletions

View file

@ -183,6 +183,7 @@ class EnumTest {
engine.ElementKind.GENERIC_FUNCTION_TYPE: ElementKind.FUNCTION_TYPE_ALIAS,
engine.ElementKind.IMPORT: ElementKind.UNKNOWN,
engine.ElementKind.NAME: ElementKind.UNKNOWN,
engine.ElementKind.NEVER: ElementKind.UNKNOWN,
engine.ElementKind.UNIVERSE: ElementKind.UNKNOWN
});
}

View file

@ -843,25 +843,27 @@ class ElementKind implements Comparable<ElementKind> {
static const ElementKind NAME = const ElementKind('NAME', 15, "<name>");
static const ElementKind NEVER = const ElementKind('NEVER', 16, "<never>");
static const ElementKind PARAMETER =
const ElementKind('PARAMETER', 16, "parameter");
const ElementKind('PARAMETER', 17, "parameter");
static const ElementKind PREFIX =
const ElementKind('PREFIX', 17, "import prefix");
const ElementKind('PREFIX', 18, "import prefix");
static const ElementKind SETTER = const ElementKind('SETTER', 18, "setter");
static const ElementKind SETTER = const ElementKind('SETTER', 19, "setter");
static const ElementKind TOP_LEVEL_VARIABLE =
const ElementKind('TOP_LEVEL_VARIABLE', 19, "top level variable");
const ElementKind('TOP_LEVEL_VARIABLE', 20, "top level variable");
static const ElementKind FUNCTION_TYPE_ALIAS =
const ElementKind('FUNCTION_TYPE_ALIAS', 20, "function type alias");
const ElementKind('FUNCTION_TYPE_ALIAS', 21, "function type alias");
static const ElementKind TYPE_PARAMETER =
const ElementKind('TYPE_PARAMETER', 21, "type parameter");
const ElementKind('TYPE_PARAMETER', 22, "type parameter");
static const ElementKind UNIVERSE =
const ElementKind('UNIVERSE', 22, "<universe>");
const ElementKind('UNIVERSE', 23, "<universe>");
static const List<ElementKind> values = const [
CLASS,
@ -880,6 +882,7 @@ class ElementKind implements Comparable<ElementKind> {
LOCAL_VARIABLE,
METHOD,
NAME,
NEVER,
PARAMETER,
PREFIX,
SETTER,

View file

@ -350,6 +350,7 @@ const List<ErrorCode> errorCodeValues = const [
HintCode.SDK_VERSION_EQ_EQ_OPERATOR_IN_CONST_CONTEXT,
HintCode.SDK_VERSION_GT_GT_GT_OPERATOR,
HintCode.SDK_VERSION_IS_EXPRESSION_IN_CONST_CONTEXT,
HintCode.SDK_VERSION_NEVER,
HintCode.SDK_VERSION_SET_LITERAL,
HintCode.SDK_VERSION_UI_AS_CODE,
HintCode.STRICT_RAW_TYPE,

View file

@ -631,7 +631,10 @@ class ReferenceCollector {
if (node.isSynthetic) return;
var name = node.name;
if (_localScopes.contains(name) || name == 'void' || name == 'dynamic') {
if (_localScopes.contains(name) ||
name == 'void' ||
name == 'dynamic' ||
name == 'Never') {
return;
}

View file

@ -289,6 +289,8 @@ class LibraryContext {
var rootReference = Reference.root();
rootReference.getChild('dart:core').getChild('dynamic').element =
DynamicElementImpl.instance;
rootReference.getChild('dart:core').getChild('Never').element =
NeverElementImpl.instance;
elementFactory = LinkedElementFactory(
analysisContext,

View file

@ -7815,6 +7815,30 @@ class MultiplyInheritedPropertyAccessorElementImpl
}
}
/// The synthetic element representing the declaration of the type `Never`.
class NeverElementImpl extends ElementImpl implements TypeDefiningElement {
/// Return the unique instance of this class.
static NeverElementImpl get instance =>
BottomTypeImpl.instance.element as NeverElementImpl;
@override
BottomTypeImpl type;
/// Initialize a newly created instance of this class. Instances of this class
/// should <b>not</b> be created except as part of creating the type
/// associated with this element. The single instance of this class should be
/// accessed through the method [instance].
NeverElementImpl() : super('Never', -1) {
setModifier(Modifier.SYNTHETIC, true);
}
@override
ElementKind get kind => ElementKind.NEVER;
@override
T accept<T>(ElementVisitor<T> visitor) => null;
}
/// A [VariableElementImpl], which is not a parameter.
abstract class NonParameterVariableElementImpl extends VariableElementImpl {
/// The unlinked representation of the variable in the summary.

View file

@ -63,7 +63,9 @@ class BottomTypeImpl extends TypeImpl {
/**
* Prevent the creation of instances of this class.
*/
BottomTypeImpl._() : super(null, "<bottom>");
BottomTypeImpl._() : super(new NeverElementImpl(), "Never") {
(element as NeverElementImpl).type = this;
}
@override
int get hashCode => 0;

View file

@ -627,6 +627,13 @@ class HintCode extends ErrorCode {
"but this code is required to be able to run on earlier versions.",
correction: "Try updating the SDK constraints.");
/**
* The type Never is being used in code that is expected to run on versions of
* the SDK that did not support it.
*/
static const HintCode SDK_VERSION_NEVER = const HintCode(
'SDK_VERSION_NEVER', "The type Never is not yet supported.");
/**
* The for, if or spread element is being used in code that is expected to run
* on versions of the SDK that did not support them.

View file

@ -7,6 +7,7 @@ import 'dart:collection';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/java_engine.dart';
import 'package:analyzer/src/generated/source.dart';
@ -526,7 +527,7 @@ class LibraryImportScope extends Scope {
for (int i = 0; i < _importedNamespaces.length; i++) {
Element element = lookup(_importedNamespaces[i]);
if (element != null) {
if (element.library.isInSdk) {
if (element is NeverElementImpl || element.library.isInSdk) {
sdkElements.add(element);
} else {
nonSdkElements.add(element);
@ -725,6 +726,7 @@ class NamespaceBuilder {
// which is not possible for `dynamic`.
if (library.isDartCore) {
definedNames['dynamic'] = DynamicElementImpl.instance;
definedNames['Never'] = BottomTypeImpl.instance.element;
}
return new Namespace(definedNames);

View file

@ -6553,6 +6553,9 @@ class TypeNameResolver {
if (element == DynamicElementImpl.instance) {
_setElement(typeName, element);
type = DynamicTypeImpl.instance;
} else if (element is NeverElementImpl) {
_setElement(typeName, element);
type = element.type;
} else if (element is FunctionTypeAliasElement) {
_setElement(typeName, element);
type = element.type as TypeImpl;
@ -7231,7 +7234,7 @@ abstract class TypeProvider {
InterfaceType get mapType;
/// Return the type representing the built-in type 'Never'.
InterfaceType get neverType;
DartType get neverType;
/// Return a list containing all of the types that cannot be either extended
/// or implemented.
@ -7288,11 +7291,11 @@ abstract class TypeProvider {
abstract class TypeProviderBase implements TypeProvider {
@override
List<InterfaceType> get nonSubtypableTypes => <InterfaceType>[
boolType,
doubleType,
intType,
nullType,
numType,
intType,
doubleType,
boolType,
stringType
];
@ -7321,18 +7324,12 @@ class TypeProviderImpl extends TypeProviderBase {
/// The type representing the built-in type 'bool'.
InterfaceType _boolType;
/// The type representing the type 'bottom'.
DartType _bottomType;
/// The type representing the built-in type 'double'.
InterfaceType _doubleType;
/// The type representing the built-in type 'Deprecated'.
InterfaceType _deprecatedType;
/// The type representing the built-in type 'dynamic'.
DartType _dynamicType;
/// The type representing the built-in type 'Function'.
InterfaceType _functionType;
@ -7375,9 +7372,6 @@ class TypeProviderImpl extends TypeProviderBase {
/// An shared object representing the value 'null'.
DartObjectImpl _nullObject;
/// The type representing the type 'Never'.
InterfaceType _neverType;
/// The type representing the type 'Null'.
InterfaceType _nullType;
@ -7418,7 +7412,7 @@ class TypeProviderImpl extends TypeProviderBase {
InterfaceType get boolType => _boolType;
@override
DartType get bottomType => _bottomType;
DartType get bottomType => BottomTypeImpl.instance;
@override
InterfaceType get deprecatedType => _deprecatedType;
@ -7427,7 +7421,7 @@ class TypeProviderImpl extends TypeProviderBase {
InterfaceType get doubleType => _doubleType;
@override
DartType get dynamicType => _dynamicType;
DartType get dynamicType => DynamicTypeImpl.instance;
@override
InterfaceType get functionType => _functionType;
@ -7469,7 +7463,7 @@ class TypeProviderImpl extends TypeProviderBase {
InterfaceType get mapType => _mapType;
@override
InterfaceType get neverType => _neverType;
DartType get neverType => BottomTypeImpl.instance;
@override
DartObjectImpl get nullObject {
@ -7509,16 +7503,6 @@ class TypeProviderImpl extends TypeProviderBase {
@override
InterfaceType get typeType => _typeType;
InterfaceType _createNever(Namespace namespace) {
// TODO(brianwilkerson) Remove this method when the class is defined in the
// SDK.
CompilationUnitElement compilationUnit =
boolType.element.getAncestor((e) => e is CompilationUnitElement);
ClassElementImpl element = ElementFactory.classElement('Never', objectType);
element.enclosingElement = compilationUnit;
return element.type;
}
/// Return the type with the given [typeName] from the given [namespace], or
/// `null` if there is no class with the given name.
InterfaceType _getType(Namespace namespace, String typeName) {
@ -7541,10 +7525,8 @@ class TypeProviderImpl extends TypeProviderBase {
new NamespaceBuilder().createPublicNamespaceForLibrary(asyncLibrary);
_boolType = _getType(coreNamespace, 'bool');
_bottomType = BottomTypeImpl.instance;
_deprecatedType = _getType(coreNamespace, 'Deprecated');
_doubleType = _getType(coreNamespace, 'double');
_dynamicType = DynamicTypeImpl.instance;
_functionType = _getType(coreNamespace, 'Function');
_futureOrType = _getType(asyncNamespace, 'FutureOr');
_futureType = _getType(asyncNamespace, 'Future');
@ -7552,8 +7534,6 @@ class TypeProviderImpl extends TypeProviderBase {
_iterableType = _getType(coreNamespace, 'Iterable');
_listType = _getType(coreNamespace, 'List');
_mapType = _getType(coreNamespace, 'Map');
_neverType =
_getType(coreNamespace, 'Never') ?? _createNever(coreNamespace);
_nullType = _getType(coreNamespace, 'Null');
_numType = _getType(coreNamespace, 'num');
_objectType = _getType(coreNamespace, 'Object');
@ -7563,13 +7543,13 @@ class TypeProviderImpl extends TypeProviderBase {
_stringType = _getType(coreNamespace, 'String');
_symbolType = _getType(coreNamespace, 'Symbol');
_typeType = _getType(coreNamespace, 'Type');
_futureDynamicType = _futureType.instantiate(<DartType>[_dynamicType]);
_futureDynamicType = _futureType.instantiate(<DartType>[dynamicType]);
_futureNullType = _futureType.instantiate(<DartType>[_nullType]);
_iterableDynamicType = _iterableType.instantiate(<DartType>[_dynamicType]);
_iterableDynamicType = _iterableType.instantiate(<DartType>[dynamicType]);
_iterableObjectType = _iterableType.instantiate(<DartType>[_objectType]);
_mapObjectObjectType =
_mapType.instantiate(<DartType>[_objectType, _objectType]);
_streamDynamicType = _streamType.instantiate(<DartType>[_dynamicType]);
_streamDynamicType = _streamType.instantiate(<DartType>[dynamicType]);
// FutureOr<T> is still fairly new, so if we're analyzing an SDK that
// doesn't have it yet, create an element for it.
_futureOrType ??= createPlaceholderFutureOr(_futureType, _objectType);

View file

@ -81,6 +81,12 @@ class SdkConstraintVerifier extends RecursiveAstVisitor<void> {
bool get checkFutureAndStream => _checkFutureAndStream ??=
!before_2_1_0.intersect(_versionConstraint).isEmpty;
/// Return `true` if references to the non-nullable features need to be
/// checked.
// TODO(brianwilkerson) Implement this as a version check when a version has
// been selected.
bool get checkNnbd => true;
/// Return `true` if references to set literals need to be checked.
bool get checkSetLiterals =>
_checkSetLiterals ??= !before_2_2_0.intersect(_versionConstraint).isEmpty;
@ -214,6 +220,8 @@ class SdkConstraintVerifier extends RecursiveAstVisitor<void> {
}
_errorReporter.reportErrorForNode(
HintCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, node, [element.name]);
} else if (checkNnbd && element == _typeProvider.neverType.element) {
_errorReporter.reportErrorForNode(HintCode.SDK_VERSION_NEVER, node);
}
}

View file

@ -5390,7 +5390,6 @@ class TypeProviderForLink extends TypeProviderBase {
InterfaceType _listType;
InterfaceType _mapType;
InterfaceType _mapObjectObjectType;
InterfaceType _neverType;
InterfaceType _nullType;
InterfaceType _numType;
InterfaceType _objectType;
@ -5475,8 +5474,7 @@ class TypeProviderForLink extends TypeProviderBase {
_mapType ??= _buildInterfaceType(_linker.coreLibrary, 'Map');
@override
InterfaceType get neverType =>
_neverType ??= _buildInterfaceType(_linker.coreLibrary, 'Never');
DartType get neverType => BottomTypeImpl.instance;
@override
DartObjectImpl get nullObject {

View file

@ -128,7 +128,6 @@ class SummaryTypeProvider extends TypeProviderBase {
InterfaceType _listType;
InterfaceType _mapType;
InterfaceType _mapObjectObjectType;
InterfaceType _neverType;
DartObjectImpl _nullObject;
InterfaceType _nullType;
InterfaceType _numType;
@ -267,10 +266,7 @@ class SummaryTypeProvider extends TypeProviderBase {
}
@override
InterfaceType get neverType {
assert(_coreLibrary != null);
return _neverType ??= _getType(_coreLibrary, 'Never');
}
DartType get neverType => BottomTypeImpl.instance;
@override
DartObjectImpl get nullObject {

View file

@ -169,6 +169,7 @@ class SourceLibraryBuilder {
}
if ('$uri' == 'dart:core') {
localScope.declare('dynamic', reference.getChild('dynamic'));
localScope.declare('Never', reference.getChild('Never'));
}
}

View file

@ -64,6 +64,8 @@ class Linker {
) {
var dynamicRef = rootReference.getChild('dart:core').getChild('dynamic');
dynamicRef.element = DynamicElementImpl.instance;
var neverRef = rootReference.getChild('dart:core').getChild('Never');
neverRef.element = NeverElementImpl.instance;
linkingBundleContext = LinkingBundleContext(dynamicRef);

View file

@ -92,7 +92,7 @@ typedef F<T> = T Function(T);
{t: intType},
{t: BottomTypeImpl.instance},
).substituteType(type);
assertElementTypeString(result, '(<bottom>) → int');
assertElementTypeString(result, '(Never) → int');
}
}

View file

@ -0,0 +1,38 @@
// Copyright (c) 2019, 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/analysis/features.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'driver_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ImportResolutionTest);
defineReflectiveTests(ImportResolutionWithNnbdTest);
});
}
@reflectiveTest
class ImportResolutionTest extends DriverResolutionTest {
test_overrideCoreType_Never() async {
newFile('/test/lib/declares_never.dart', content: '''
class Never {}
''');
assertNoErrorsInCode(r'''
import 'declares_never.dart';
Never f() => throw 'foo';
''');
}
}
@reflectiveTest
class ImportResolutionWithNnbdTest extends ImportResolutionTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = new FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
}

View file

@ -26,6 +26,7 @@ import 'instance_member_inference_mixin_test.dart'
as instance_member_inference_mixin;
import 'method_invocation_test.dart' as method_invocation;
import 'mixin_test.dart' as mixin_resolution;
import 'namespace_test.dart' as namespace;
import 'non_nullable_test.dart' as non_nullable;
import 'optional_const_test.dart' as optional_const;
import 'property_access_test.dart' as property_access;
@ -53,6 +54,7 @@ main() {
instance_member_inference_mixin.main();
method_invocation.main();
mixin_resolution.main();
namespace.main();
non_nullable.main();
optional_const.main();
property_access.main();

View file

@ -0,0 +1,36 @@
// Copyright (c) 2019, 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/analysis/features.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/driver_resolution.dart';
main() {
defineReflectiveSuite(() {
// defineReflectiveTests(ExtendsNonClassTest);
defineReflectiveTests(ExtendsNonClassWithNnbdTest);
});
}
@reflectiveTest
class ExtendsNonClassTest extends DriverResolutionTest {}
@reflectiveTest
class ExtendsNonClassWithNnbdTest extends ExtendsNonClassTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = new FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
test_Never() async {
await assertErrorsInCode('''
class A extends Never {}
''', [
error(CompileTimeErrorCode.EXTENDS_NON_CLASS, 16, 5),
]);
}
}

View file

@ -0,0 +1,36 @@
// Copyright (c) 2019, 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/analysis/features.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/driver_resolution.dart';
main() {
defineReflectiveSuite(() {
// defineReflectiveTests(ImplementsNonClassTest);
defineReflectiveTests(ImplementsNonClassWithNnbdTest);
});
}
@reflectiveTest
class ImplementsNonClassTest extends DriverResolutionTest {}
@reflectiveTest
class ImplementsNonClassWithNnbdTest extends ImplementsNonClassTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = new FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
test_Never() async {
await assertErrorsInCode('''
class A implements Never {}
''', [
error(CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, 19, 5),
]);
}
}

View file

@ -0,0 +1,36 @@
// Copyright (c) 2019, 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/analysis/features.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/driver_resolution.dart';
main() {
defineReflectiveSuite(() {
// defineReflectiveTests(MixinOfNonClassTest);
defineReflectiveTests(MixinOfNonClassWithNnbdTest);
});
}
@reflectiveTest
class MixinOfNonClassTest extends DriverResolutionTest {}
@reflectiveTest
class MixinOfNonClassWithNnbdTest extends MixinOfNonClassTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = new FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
test_Never() async {
await assertErrorsInCode('''
class A with Never {}
''', [
error(CompileTimeErrorCode.MIXIN_OF_NON_CLASS, 13, 5),
]);
}
}

View file

@ -27,7 +27,6 @@ class MixinSuperClassConstraintNonInterfaceWithNnbdTest
..contextFeatures = new FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
@failingTest
test_Never() async {
await assertErrorsInCode('''
mixin M on Never {}

View file

@ -0,0 +1,48 @@
// Copyright (c) 2018, 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/analysis/features.dart';
import 'package:analyzer/src/dart/error/hint_codes.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import 'sdk_constraint_verifier_support.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(SdkVersionNeverTest);
});
}
@reflectiveTest
class SdkVersionNeverTest extends SdkConstraintVerifierTest {
@override
AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl()
..contextFeatures = new FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
@failingTest
test_equals() async {
// This test cannot pass because there is no version number that is equal to
// when non-nullable was enabled.
await verifyVersion('2.1.0', '''
Never sink;
''');
}
@failingTest
test_greaterThan() async {
// This test cannot pass because there is no version number that is equal to
// when non-nullable was enabled.
await verifyVersion('2.1.0', '''
Never sink;
''');
}
test_lessThan() async {
await verifyVersion('2.3.0', '''
Never sink;
''', errorCodes: [HintCode.SDK_VERSION_NEVER]);
}
}

View file

@ -32,7 +32,9 @@ import 'duplicate_import_test.dart' as duplicate_import;
import 'equal_elements_in_const_set_test.dart' as equal_elements_in_const_set;
import 'equal_keys_in_const_map_test.dart' as equal_keys_in_const_map;
import 'expression_in_map_test.dart' as expression_in_map;
import 'extends_non_class_test.dart' as extends_non_class;
import 'final_not_initialized_test.dart' as final_not_initialized;
import 'implements_non_class_test.dart' as implements_non_class;
import 'implicit_this_reference_in_initializer_test.dart'
as implicit_this_reference_in_initializer;
import 'import_deferred_library_with_load_function_test.dart'
@ -69,6 +71,7 @@ import 'missing_default_value_for_parameter_test.dart'
as missing_default_value_for_paramter;
import 'missing_required_param_test.dart' as missing_required_param;
import 'missing_return_test.dart' as missing_return;
import 'mixin_of_non_class_test.dart' as mixin_of_non_class;
import 'mixin_on_sealed_class_test.dart' as mixin_on_sealed_class;
import 'mixin_super_class_constraint_non_interface_test.dart'
as mixin_super_class_constraint_non_interface;
@ -128,6 +131,7 @@ import 'sdk_version_gt_gt_gt_operator_test.dart'
as sdk_version_gt_gt_gt_operator;
import 'sdk_version_is_expression_in_const_context_test.dart'
as sdk_version_is_expression_in_const_context;
import 'sdk_version_never_test.dart' as sdk_version_never;
import 'sdk_version_set_literal_test.dart' as sdk_version_set_literal;
import 'sdk_version_ui_as_code_test.dart' as sdk_version_ui_as_code;
import 'set_element_type_not_assignable_test.dart'
@ -184,7 +188,9 @@ main() {
equal_elements_in_const_set.main();
equal_keys_in_const_map.main();
expression_in_map.main();
extends_non_class.main();
final_not_initialized.main();
implements_non_class.main();
implicit_this_reference_in_initializer.main();
import_deferred_library_with_load_function.main();
invalid_assignment.main();
@ -209,6 +215,7 @@ main() {
missing_default_value_for_paramter.main();
missing_required_param.main();
missing_return.main();
mixin_of_non_class.main();
mixin_on_sealed_class.main();
mixin_super_class_constraint_non_interface.main();
must_be_immutable.main();
@ -248,6 +255,7 @@ main() {
sdk_version_eq_eq_operator.main();
sdk_version_gt_gt_gt_operator.main();
sdk_version_is_expression_in_const_context.main();
sdk_version_never.main();
sdk_version_set_literal.main();
sdk_version_ui_as_code.main();
set_element_type_not_assignable.main();

View file

@ -327,7 +327,7 @@ class C {
ClassElementForLink_Class cls = library.getContainedName('C');
expect(cls.fields, hasLength(1));
var field = cls.fields[0];
expect(field.type.toString(), '(<bottom>) → int');
expect(field.type.toString(), '(Never) → int');
}
void test_inferredType_instanceField_dynamic() {

View file

@ -83,6 +83,8 @@ class ResynthesizeAst2Test extends ResynthesizeTestStrategyTwoPhase
var rootReference = Reference.root();
rootReference.getChild('dart:core').getChild('dynamic').element =
DynamicElementImpl.instance;
rootReference.getChild('dart:core').getChild('Never').element =
NeverElementImpl.instance;
var elementFactory = LinkedElementFactory(
analysisContext,

View file

@ -8969,7 +8969,7 @@ final v = f() ? <T>(T t) => 0 : <T>(T t) => 1;
bool f() => true;
''');
checkElementText(library, r'''
final int Function(<bottom>) v;
final int Function(Never) v;
bool f() {}
''');
}

View file

@ -9504,7 +9504,7 @@ var v = extract(f);
UnlinkedVariable variable = serializeVariableText('int v = null;');
expect(variable.initializer.returnType, isNull);
checkInferredTypeSlot(
variable.initializer.inferredReturnTypeSlot, null, '*bottom*',
variable.initializer.inferredReturnTypeSlot, null, 'Never',
onlyInStrongMode: false);
}
@ -10827,7 +10827,7 @@ bool f() => true;
EntityRef inferredType = getTypeRefForSlot(variable.inferredTypeSlot);
checkLinkedTypeRef(inferredType.syntheticReturnType, 'dart:core', 'int');
expect(inferredType.syntheticParams, hasLength(1));
checkLinkedTypeRef(inferredType.syntheticParams[0].type, null, '*bottom*');
checkLinkedTypeRef(inferredType.syntheticParams[0].type, null, 'Never');
}
test_syntheticFunctionType_inGenericClass() {

View file

@ -27,7 +27,7 @@ ImportLibraryRequest importLibraryElementImpl({
}
var requestedElements = requestedLibrary.exportNamespace.definedNames;
_removeEntryForDynamic(requestedElements);
_removeEntriesForDynamicAndNever(requestedElements);
// Find URIs of all libraries that import the requested name into the target.
var unprefixedNameUriSet = Set<Uri>();
@ -145,11 +145,13 @@ ImportLibraryRequest importLibraryElementImpl({
return ImportLibraryRequest(requestedLibraryUri, prefix);
}
/// The type `dynamic` is part of 'dart:core', but has no library.
void _removeEntryForDynamic(Map<String, Element> requestedElements) {
/// The types `dynamic` and `Never` are part of 'dart:core', but have no
/// library.
void _removeEntriesForDynamicAndNever(Map<String, Element> requestedElements) {
requestedElements.removeWhere((_, element) {
if (element.librarySource == null) {
assert(element.displayName == 'dynamic');
assert(
element.displayName == 'dynamic' || element.displayName == 'Never');
return true;
}
return false;