Skip to content

Commit

Permalink
Use 'isNonNullableByDefault' as the flag name everywhere.
Browse files Browse the repository at this point in the history
We used different names at different places, I propose using this
single name everywhere. Hopefully I updated them all.

R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I0fea2799b9a40526c4f0194a8a81812bdf788c90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127722
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
scheglov committed Dec 9, 2019
1 parent 86723cd commit ded753a
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 63 deletions.
12 changes: 6 additions & 6 deletions pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ElementHolder {
class ResolutionVisitor extends RecursiveAstVisitor<void> {
final TypeProvider _typeProvider;
final CompilationUnitElementImpl _unitElement;
final bool _nonNullableEnabled;
final bool _isNonNullableByDefault;
final ErrorReporter _errorReporter;
final AstRewriter _astRewriter;
final TypeNameResolver _typeNameResolver;
Expand Down Expand Up @@ -96,13 +96,13 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
var libraryElement = unitElement.library;
var typeProvider = libraryElement.typeProvider;
var unitSource = unitElement.source;
var nonNullableEnabled = featureSet.isEnabled(Feature.non_nullable);
var isNonNullableByDefault = featureSet.isEnabled(Feature.non_nullable);
var errorReporter = ErrorReporter(errorListener, unitSource);

var typeNameResolver = TypeNameResolver(
libraryElement.typeSystem,
typeProvider,
nonNullableEnabled,
isNonNullableByDefault,
libraryElement,
unitSource,
errorListener,
Expand All @@ -111,7 +111,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
return ResolutionVisitor._(
typeProvider,
unitElement,
nonNullableEnabled,
isNonNullableByDefault,
errorReporter,
AstRewriter(libraryElement, errorReporter),
typeNameResolver,
Expand All @@ -124,7 +124,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {
ResolutionVisitor._(
this._typeProvider,
this._unitElement,
this._nonNullableEnabled,
this._isNonNullableByDefault,
this._errorReporter,
this._astRewriter,
this._typeNameResolver,
Expand Down Expand Up @@ -1132,7 +1132,7 @@ class ResolutionVisitor extends RecursiveAstVisitor<void> {

NullabilitySuffix _getNullability(bool hasQuestion) {
NullabilitySuffix nullability;
if (_nonNullableEnabled) {
if (_isNonNullableByDefault) {
if (hasQuestion) {
nullability = NullabilitySuffix.question;
} else {
Expand Down
9 changes: 5 additions & 4 deletions pkg/analyzer/lib/src/error/best_practices_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
/// The [LinterContext] used for possible const calculations.
LinterContext _linterContext;

/// Is `true` if NNBD is enabled for the library being analyzed.
final bool _isNonNullable;
/// Is `true` if the library being analyzed is non-nullable by default.
final bool _isNonNullableByDefault;

/// True if inference failures should be reported, otherwise false.
final bool _strictInference;
Expand All @@ -96,7 +96,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
strictInference: false,
typeProvider: typeProvider,
),
_isNonNullable = unit.featureSet.isEnabled(Feature.non_nullable),
_isNonNullableByDefault =
unit.featureSet.isEnabled(Feature.non_nullable),
_strictInference =
(analysisOptions as AnalysisOptionsImpl).strictInference,
_inheritanceManager = inheritanceManager,
Expand Down Expand Up @@ -1085,7 +1086,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {

/// Produce several null-aware related hints.
void _checkForNullAwareHints(Expression node, Token operator) {
if (_isNonNullable) {
if (_isNonNullableByDefault) {
return;
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/analyzer/lib/src/error/dead_code_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class DeadCodeVerifier extends RecursiveAstVisitor<void> {
/// The object used to track the usage of labels within a given label scope.
_LabelTracker labelTracker;

/// Is `true` if this unit has been parsed as non-nullable.
final bool _isNonNullableUnit;
/// Is `true` if the library being analyzed is non-nullable by default.
final bool _isNonNullableByDefault;

/// Initialize a newly created dead code verifier that will report dead code
/// to the given [errorReporter] and will use the given [typeSystem] if one is
Expand All @@ -45,7 +45,7 @@ class DeadCodeVerifier extends RecursiveAstVisitor<void> {
strictInference: false,
typeProvider: null,
),
_isNonNullableUnit = featureSet.isEnabled(Feature.non_nullable);
_isNonNullableByDefault = featureSet.isEnabled(Feature.non_nullable);

@override
void visitAssignmentExpression(AssignmentExpression node) {
Expand Down Expand Up @@ -395,7 +395,7 @@ class DeadCodeVerifier extends RecursiveAstVisitor<void> {
}

void _checkForDeadNullCoalesce(TypeImpl lhsType, Expression rhs) {
if (_isNonNullableUnit && _typeSystem.isNonNullable(lhsType)) {
if (_isNonNullableByDefault && _typeSystem.isNonNullable(lhsType)) {
_errorReporter.reportErrorForNode(HintCode.DEAD_CODE, rhs, []);
}
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/analyzer/lib/src/generated/error_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
_enclosingClass = classElement;
}

bool get _isNonNullable =>
bool get _isNonNullableByDefault =>
_featureSet?.isEnabled(Feature.non_nullable) ?? false;

@override
Expand Down Expand Up @@ -1608,7 +1608,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {

if (field.isFinal) {
notInitFinalFields.add(field);
} else if (_isNonNullable &&
} else if (_isNonNullableByDefault &&
_typeSystem.isPotentiallyNonNullable(field.type)) {
notInitNonNullableFields.add(field);
}
Expand Down Expand Up @@ -3039,7 +3039,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
CompileTimeErrorCode.CONST_NOT_INITIALIZED,
variable.name,
[variable.name.name]);
} else if (!_isNonNullable || !variable.isLate) {
} else if (!_isNonNullableByDefault || !variable.isLate) {
_errorReporter.reportErrorForNode(
StaticWarningCode.FINAL_NOT_INITIALIZED,
variable.name,
Expand Down Expand Up @@ -3541,7 +3541,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {

void _checkForListConstructor(
InstanceCreationExpression node, InterfaceType type) {
if (!_isNonNullable) return;
if (!_isNonNullableByDefault) return;

if (node.constructorName.name == null &&
node.argumentList.arguments.length == 1 &&
Expand Down Expand Up @@ -4246,7 +4246,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
void _checkForNotInitializedNonNullableInstanceFields(
FieldDeclaration fieldDeclaration,
) {
if (!_isNonNullable) return;
if (!_isNonNullableByDefault) return;

if (fieldDeclaration.isStatic) return;
var fields = fieldDeclaration.fields;
Expand Down Expand Up @@ -4278,7 +4278,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
void _checkForNotInitializedNonNullableVariable(
VariableDeclarationList node,
) {
if (!_isNonNullable) {
if (!_isNonNullableByDefault) {
return;
}

Expand Down Expand Up @@ -4318,7 +4318,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
*/
bool _checkForNullableDereference(Expression expression) {
if (expression == null ||
!_isNonNullable ||
!_isNonNullableByDefault ||
expression.staticType == null ||
expression.staticType.isDynamic ||
!_typeSystem.isPotentiallyNullable(expression.staticType)) {
Expand Down Expand Up @@ -5033,7 +5033,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
}

void _checkForUnnecessaryNullAware(Expression target, Token operator) {
if (!_isNonNullable) {
if (!_isNonNullableByDefault) {
return;
}

Expand Down Expand Up @@ -5613,7 +5613,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
}

void _checkUseOfDefaultValuesInParameters(FormalParameterList node) {
if (!_isNonNullable) return;
if (!_isNonNullableByDefault) return;

AstNode parent = node.parent;
var defaultValuesAreAllowed = parent is ConstructorDeclaration ||
Expand Down Expand Up @@ -5983,7 +5983,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
/// If in a legacy library, return the legacy version of the [type].
/// Otherwise, return the original type.
DartType _toLegacyType(DartType type) {
if (_isNonNullable) return type;
if (_isNonNullableByDefault) return type;
return NullabilityEliminator.perform(_typeProvider, type);
}

Expand Down
31 changes: 17 additions & 14 deletions pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class InferenceContext {
if (_returnStack.isNotEmpty && _inferredReturn.isNotEmpty) {
// If NNBD, and the function body end is reachable, infer nullable.
// If legacy, we consider the end as always reachable, and return Null.
if (_resolver._nonNullableEnabled) {
if (_resolver._isNonNullableByDefault) {
var flow = _resolver._flowAnalysis?.flow;
if (flow != null && flow.isReachable) {
addReturnOrYieldType(_typeProvider.nullType);
Expand Down Expand Up @@ -633,15 +633,16 @@ class ResolverVisitor extends ScopedVisitor {
}

NullabilitySuffix get noneOrStarSuffix {
return _nonNullableEnabled
return _isNonNullableByDefault
? NullabilitySuffix.none
: NullabilitySuffix.star;
}

/**
* Return `true` if NNBD is enabled for this compilation unit.
*/
bool get _nonNullableEnabled => _featureSet.isEnabled(Feature.non_nullable);
bool get _isNonNullableByDefault =>
_featureSet.isEnabled(Feature.non_nullable);

/// Return the static element associated with the given expression whose type
/// can be overridden, or `null` if there is no element whose type can be
Expand Down Expand Up @@ -754,14 +755,14 @@ class ResolverVisitor extends ScopedVisitor {
/// If in a legacy library, return the legacy view on the [element].
/// Otherwise, return the original element.
T toLegacyElement<T extends Element>(T element) {
if (_nonNullableEnabled) return element;
if (_isNonNullableByDefault) return element;
return Member.legacy(element);
}

/// If in a legacy library, return the legacy version of the [type].
/// Otherwise, return the original type.
DartType toLegacyTypeIfOptOut(DartType type) {
if (_nonNullableEnabled) return type;
if (_isNonNullableByDefault) return type;
return NullabilityEliminator.perform(typeProvider, type);
}

Expand Down Expand Up @@ -1690,7 +1691,7 @@ class ResolverVisitor extends ScopedVisitor {
@override
void visitIndexExpression(IndexExpression node) {
node.target?.accept(this);
if (node.isNullAware && _nonNullableEnabled) {
if (node.isNullAware && _isNonNullableByDefault) {
_flowAnalysis.flow.nullAwareAccess_rightBegin(node.target);
unfinishedNullShorts.add(node.nullShortingTermination);
}
Expand Down Expand Up @@ -1888,7 +1889,7 @@ class ResolverVisitor extends ScopedVisitor {
// to be visited in the context of the property access node.
//
node.target?.accept(this);
if (node.isNullAware && _nonNullableEnabled) {
if (node.isNullAware && _isNonNullableByDefault) {
_flowAnalysis.flow.nullAwareAccess_rightBegin(node.target);
unfinishedNullShorts.add(node.nullShortingTermination);
}
Expand Down Expand Up @@ -2421,7 +2422,7 @@ class ResolverVisitor extends ScopedVisitor {
isConst: isConst,
errorReporter: errorReporter,
errorNode: errorNode,
isNonNullableByDefault: _nonNullableEnabled,
isNonNullableByDefault: _isNonNullableByDefault,
);
if (typeArguments != null) {
return uninstantiatedType.instantiate(typeArguments);
Expand Down Expand Up @@ -3410,7 +3411,7 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
class TypeNameResolver {
final TypeSystemImpl typeSystem;
final DartType dynamicType;
final bool isNonNullableUnit;
final bool isNonNullableByDefault;
final AnalysisOptionsImpl analysisOptions;
final LibraryElement definingLibrary;
final Source source;
Expand All @@ -3435,7 +3436,7 @@ class TypeNameResolver {
TypeNameResolver(
this.typeSystem,
TypeProvider typeProvider,
this.isNonNullableUnit,
this.isNonNullableByDefault,
this.definingLibrary,
this.source,
this.errorListener,
Expand All @@ -3444,7 +3445,9 @@ class TypeNameResolver {
analysisOptions = definingLibrary.context.analysisOptions;

NullabilitySuffix get _noneOrStarSuffix {
return isNonNullableUnit ? NullabilitySuffix.none : NullabilitySuffix.star;
return isNonNullableByDefault
? NullabilitySuffix.none
: NullabilitySuffix.star;
}

/// Report an error with the given error code and arguments.
Expand Down Expand Up @@ -3830,7 +3833,7 @@ class TypeNameResolver {

NullabilitySuffix _getNullability(bool hasQuestion) {
NullabilitySuffix nullability;
if (isNonNullableUnit) {
if (isNonNullableByDefault) {
if (hasQuestion) {
nullability = NullabilitySuffix.question;
} else {
Expand Down Expand Up @@ -3894,7 +3897,7 @@ class TypeNameResolver {
declaredReturnType: typeElement.thisType,
argumentTypes: const [],
contextReturnType: enclosingClassElement.thisType,
isNonNullableByDefault: isNonNullableUnit,
isNonNullableByDefault: isNonNullableByDefault,
);
}
}
Expand Down Expand Up @@ -4023,7 +4026,7 @@ class TypeNameResolver {
if (node.question != null) {
_reportInvalidNullableType(node);
}
if (isNonNullableUnit) {
if (isNonNullableByDefault) {
nullabilitySuffix = NullabilitySuffix.none;
} else {
nullabilitySuffix = NullabilitySuffix.star;
Expand Down
Loading

0 comments on commit ded753a

Please sign in to comment.