From d16bedc2e143bc73a374b93401adcd03a60628a4 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Tue, 30 Apr 2024 15:42:58 -0700 Subject: [PATCH] Bump analyzer to 6.5.0 (#3763) * Bump analyzer to 6.5.0 --- .github/workflows/test.yaml | 4 +- .../templates.runtime_renderers.dart | 23 ++++++---- lib/src/model/accessor.dart | 4 +- lib/src/model/annotation.dart | 4 +- lib/src/model/comment_referable.dart | 2 +- lib/src/model/inheriting_container.dart | 42 ++++++------------- lib/src/model/library.dart | 2 +- lib/src/model/method.dart | 6 +-- lib/src/model/model_element.dart | 2 +- lib/src/model/package_graph.dart | 2 +- lib/src/mustachio/renderer_base.dart | 12 +++--- pubspec.yaml | 2 +- test/mustachio/aot_compiler_builder_test.dart | 2 +- .../runtime_renderer_builder_test.dart | 4 +- tool/mustachio/codegen_runtime_renderer.dart | 20 +++++---- tool/mustachio/utilities.dart | 6 +-- 16 files changed, 62 insertions(+), 75 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dd1e8ebfc7..47847870b8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -22,7 +22,9 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - sdk: [dev, stable] + # TODO(srawlins): Re-enable stable after 3.4.0 ships. + # sdk: [dev, stable] + sdk: [dev] job: [main, flutter, packages, sdk-docs] include: - os: macos-latest diff --git a/lib/src/generator/templates.runtime_renderers.dart b/lib/src/generator/templates.runtime_renderers.dart index 0fe537c048..7e226401d1 100644 --- a/lib/src/generator/templates.runtime_renderers.dart +++ b/lib/src/generator/templates.runtime_renderers.dart @@ -2668,7 +2668,7 @@ class _Renderer_Container extends RendererBase { renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable( - c, remainingNames, 'Set'), + c, remainingNames, 'Set'), renderIterable: (CT_ c, RendererBase r, List ast, StringSink sink) { return c.allElements.map((e) => renderSimple( @@ -10203,7 +10203,7 @@ class _Renderer_ModelElement extends RendererBase { renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable( - c, remainingNames, 'Iterable'), + c, remainingNames, 'Iterable'), renderIterable: (CT_ c, RendererBase r, List ast, StringSink sink) { return c.displayedCategories.map((e) => @@ -12036,7 +12036,7 @@ class _Renderer_Package extends RendererBase { renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable( - c, remainingNames, 'Map'), + c, remainingNames, 'Map'), isNullValue: (CT_ c) => false, renderValue: (CT_ c, RendererBase r, List ast, StringSink sink) { @@ -12202,7 +12202,7 @@ class _Renderer_Package extends RendererBase { renderVariable: (CT_ c, Property self, List remainingNames) => self.renderSimpleVariable( - c, remainingNames, 'Map>'), + c, remainingNames, 'Map>'), isNullValue: (CT_ c) => false, renderValue: (CT_ c, RendererBase r, List ast, StringSink sink) { @@ -15762,7 +15762,6 @@ const _invisibleGetters = { 'isDartCoreObject', 'isExhaustive', 'isFinal', - 'isInline', 'isInterface', 'isMixinApplication', 'isMixinClass', @@ -15926,6 +15925,7 @@ const _invisibleGetters = { 'hasAlwaysThrows', 'hasDeprecated', 'hasDoNotStore', + 'hasDoNotSubmit', 'hasFactory', 'hasImmutable', 'hasInternal', @@ -15933,6 +15933,7 @@ const _invisibleGetters = { 'hasIsTestGroup', 'hasJS', 'hasLiteral', + 'hasMustBeConst', 'hasMustBeOverridden', 'hasMustCallSuper', 'hasNonVirtual', @@ -15984,6 +15985,7 @@ const _invisibleGetters = { 'hasAlwaysThrows', 'hasDeprecated', 'hasDoNotStore', + 'hasDoNotSubmit', 'hasFactory', 'hasImmutable', 'hasImplicitReturnType', @@ -15992,6 +15994,7 @@ const _invisibleGetters = { 'hasIsTestGroup', 'hasJS', 'hasLiteral', + 'hasMustBeConst', 'hasMustBeOverridden', 'hasMustCallSuper', 'hasNonVirtual', @@ -16015,7 +16018,6 @@ const _invisibleGetters = { 'isExtensionTypeMember', 'isExternal', 'isGenerator', - 'isLegacy', 'isOperator', 'isPrivate', 'isPublic', @@ -16247,6 +16249,7 @@ const _invisibleGetters = { 'hasAlwaysThrows', 'hasDeprecated', 'hasDoNotStore', + 'hasDoNotSubmit', 'hasFactory', 'hasImmutable', 'hasInternal', @@ -16254,6 +16257,7 @@ const _invisibleGetters = { 'hasIsTestGroup', 'hasJS', 'hasLiteral', + 'hasMustBeConst', 'hasMustBeOverridden', 'hasMustCallSuper', 'hasNonVirtual', @@ -16271,7 +16275,6 @@ const _invisibleGetters = { 'hasVisibleOutsideTemplate', 'hashCode', 'id', - 'isLegacy', 'isPrivate', 'isPublic', 'isSynthetic', @@ -16399,6 +16402,7 @@ const _invisibleGetters = { 'hasDefaultValue', 'hasDeprecated', 'hasDoNotStore', + 'hasDoNotSubmit', 'hasFactory', 'hasImmutable', 'hasImplicitType', @@ -16407,6 +16411,7 @@ const _invisibleGetters = { 'hasIsTestGroup', 'hasJS', 'hasLiteral', + 'hasMustBeConst', 'hasMustBeOverridden', 'hasMustCallSuper', 'hasNonVirtual', @@ -16430,7 +16435,6 @@ const _invisibleGetters = { 'isFinal', 'isInitializingFormal', 'isLate', - 'isLegacy', 'isPrivate', 'isPublic', 'isStatic', @@ -16467,7 +16471,8 @@ const _invisibleGetters = { 'isGetter', 'isSetter', 'runtimeType', - 'variable' + 'variable', + 'variable2' }, 'Scope': {'hashCode', 'runtimeType'}, 'TemplateOptions': { diff --git a/lib/src/model/accessor.dart b/lib/src/model/accessor.dart index 7e42a5dda1..30d77d2b56 100644 --- a/lib/src/model/accessor.dart +++ b/lib/src/model/accessor.dart @@ -45,9 +45,9 @@ class Accessor extends ModelElement { bool get isSynthetic => element.isSynthetic; - // The [enclosingCombo] where this element was defined. + /// The [enclosingCombo] where this element was defined. late final GetterSetterCombo definingCombo = - getModelForElement(element.variable) as GetterSetterCombo; + getModelForElement(element.variable2!) as GetterSetterCombo; String get _sourceCode { if (!isSynthetic) { diff --git a/lib/src/model/annotation.dart b/lib/src/model/annotation.dart index 3477623cfe..672ba8d338 100644 --- a/lib/src/model/annotation.dart +++ b/lib/src/model/annotation.dart @@ -48,8 +48,8 @@ final class Annotation extends Attribute { late final ElementType _modelType = switch (_annotation.element) { ConstructorElement(:var returnType) => _packageGraph.getTypeFor(returnType, _library), - PropertyAccessorElement(:var variable) => - (_packageGraph.getModelForElement(variable) as GetterSetterCombo) + PropertyAccessorElement(:var variable2?) => + (_packageGraph.getModelForElement(variable2) as GetterSetterCombo) .modelType, _ => throw StateError( 'non-callable element used as annotation?: ${_annotation.element}') diff --git a/lib/src/model/comment_referable.dart b/lib/src/model/comment_referable.dart index b2897658af..1a5c276e07 100644 --- a/lib/src/model/comment_referable.dart +++ b/lib/src/model/comment_referable.dart @@ -105,7 +105,7 @@ mixin CommentReferable implements Nameable { if (resultElement == null) return null; ModelElement result; if (resultElement is PropertyAccessorElement) { - final variable = resultElement.variable; + final variable = resultElement.variable2!; if (variable.isSynthetic) { result = packageGraph.getModelForElement(resultElement); } else { diff --git a/lib/src/model/inheriting_container.dart b/lib/src/model/inheriting_container.dart index 17c49bf9a9..30538f314d 100644 --- a/lib/src/model/inheriting_container.dart +++ b/lib/src/model/inheriting_container.dart @@ -19,13 +19,9 @@ import 'package:meta/meta.dart'; /// Note that [Constructor]s are not considered to be modifiers so a /// [hasModifiers] override is not necessary for this mixin. mixin Constructable implements InheritingContainer { - late final List constructors = - // TODO(srawlins): Remove this and deal with the follow-on effects, when - // `.augmented` becomes non-nullable. - // ignore: invalid_null_aware_operator - (element.augmented?.constructors ?? element.constructors) - .map((e) => getModelFor(e, library) as Constructor) - .toList(growable: false); + late final List constructors = element.augmented.constructors + .map((e) => getModelFor(e, library) as Constructor) + .toList(growable: false); @override late final List publicConstructorsSorted = @@ -157,11 +153,11 @@ abstract class InheritingContainer extends Container { // The mapping of all of the inherited element names to their _concrete_ // implementation element. var concreteInheritanceMap = packageGraph.inheritanceManager - .getInheritedConcreteMap2(element.augmentedDeclarationOrSelf); + .getInheritedConcreteMap2(element.augmented.declaration); // The mapping of all inherited element names to the nearest inherited // element that they resolve to. var inheritanceMap = packageGraph.inheritanceManager - .getInheritedMap2(element.augmentedDeclarationOrSelf); + .getInheritedMap2(element.augmented.declaration); var inheritanceChainElements = inheritanceChain.map((c) => c.element).toList(growable: false); @@ -259,13 +255,9 @@ abstract class InheritingContainer extends Container { }(); @override - late final List declaredMethods = - // TODO(srawlins): Remove this and deal with the follow-on effects, when - // `.augmented` becomes non-nullable. - // ignore: invalid_null_aware_operator - (element.augmented?.methods ?? element.methods) - .map((e) => getModelFor(e, library) as Method) - .toList(growable: false); + late final List declaredMethods = element.augmented.methods + .map((e) => getModelFor(e, library) as Method) + .toList(growable: false); @override late final List typeParameters = element.typeParameters @@ -538,9 +530,9 @@ abstract class InheritingContainer extends Container { // Pick an appropriate [FieldElement] to represent this element. // Only hard when dealing with a synthetic [Field]. if (getter != null && setter == null) { - field = getterElement!.variable as FieldElement; + field = getterElement!.variable2 as FieldElement; } else if (getter == null && setter != null) { - field = setterElement!.variable as FieldElement; + field = setterElement!.variable2 as FieldElement; } else { // In this case: `getter != null && setter != null`. getter!; @@ -553,9 +545,9 @@ abstract class InheritingContainer extends Container { if (setterEnclosingElement is Class && setterEnclosingElement._isInheritingFrom( getter.enclosingElement as InheritingContainer)) { - field = setterElement!.variable as FieldElement; + field = setterElement!.variable2 as FieldElement; } else { - field = getterElement!.variable as FieldElement; + field = getterElement!.variable2 as FieldElement; } } } @@ -601,16 +593,6 @@ mixin MixedInTypes on InheritingContainer { mixedInTypes.wherePublic; } -extension on InterfaceElement { - /// This element's augmented declaration, or, if there is none, then just this - /// element itself. - InterfaceElement get augmentedDeclarationOrSelf => - // TODO(srawlins): Remove this and deal with the follow-on effects, when - // `.augmented` becomes non-nullable. - // ignore: invalid_null_aware_operator - augmented?.declaration ?? this; -} - extension on InterfaceElement { bool get isDartCoreObject => name == 'Object' && library.name == 'dart.core'; } diff --git a/lib/src/model/library.dart b/lib/src/model/library.dart index ed46923592..122e0eedbd 100644 --- a/lib/src/model/library.dart +++ b/lib/src/model/library.dart @@ -340,7 +340,7 @@ class Library extends ModelElement ..._exportedAndLocalElements.whereType(), ..._exportedAndLocalElements .whereType() - .map((a) => a.variable as TopLevelVariableElement) + .map((a) => a.variable2! as TopLevelVariableElement) }; var variables = []; for (var element in elements) { diff --git a/lib/src/model/method.dart b/lib/src/model/method.dart index c9e58c7378..fd1c530f13 100644 --- a/lib/src/model/method.dart +++ b/lib/src/model/method.dart @@ -112,11 +112,7 @@ class Method extends ModelElement return null; } var parent = element.enclosingElement as InterfaceElement; - // TODO(srawlins): Remove this and deal with the follow-on effects, when - // `.augmented` becomes non-nullable. - // ignore: invalid_null_aware_operator - var parentDeclaration = parent.augmented?.declaration ?? parent; - for (var t in parentDeclaration.allSupertypes) { + for (var t in parent.augmented.declaration.allSupertypes) { Element? e = t.getMethod(element.name); if (e != null) { assert( diff --git a/lib/src/model/model_element.dart b/lib/src/model/model_element.dart index 7c55569568..8d495ea101 100644 --- a/lib/src/model/model_element.dart +++ b/lib/src/model/model_element.dart @@ -502,7 +502,7 @@ abstract class ModelElement var lookup = l.element.exportNamespace.definedNames[topLevelElement.name!]; return switch (lookup) { - PropertyAccessorElement() => topLevelElement == lookup.variable, + PropertyAccessorElement() => topLevelElement == lookup.variable2, _ => topLevelElement == lookup, }; }).toList(growable: true); diff --git a/lib/src/model/package_graph.dart b/lib/src/model/package_graph.dart index a33727b704..1f89bd6ff5 100644 --- a/lib/src/model/package_graph.dart +++ b/lib/src/model/package_graph.dart @@ -706,7 +706,7 @@ class PackageGraph with CommentReferable, Nameable { _canonicalLibraryFor[e] = null; var searchElement = switch (e) { - PropertyAccessorElement() => e.variable, + PropertyAccessorElement() => e.variable2, GenericFunctionTypeElement() => e.enclosingElement, _ => e, }; diff --git a/lib/src/mustachio/renderer_base.dart b/lib/src/mustachio/renderer_base.dart index aca76ee8e0..8d8fbc6381 100644 --- a/lib/src/mustachio/renderer_base.dart +++ b/lib/src/mustachio/renderer_base.dart @@ -165,15 +165,15 @@ abstract class RendererBase { String get contextChainString => parent == null ? '$T' : '${parent!.contextChainString} > $T'; - /// Returns the [Property] on this renderer named [name]. + /// Returns the [Property] on this renderer named [key]. /// - /// If no property named [name] exists for this renderer, `null` is returned. + /// If no property named [key] exists for this renderer, `null` is returned. Property? getProperty(String key); - /// Resolves [names] into one or more field accesses, returning the result as + /// Resolves [node] into one or more field accesses, returning the result as /// a String. /// - /// [names] may have multiple dot-separate names, and [names] may not be a + /// [node]'s `key` may have multiple dot-separate names, and it may not be a /// valid property of _this_ context type, in which the [parent] renderer is /// referenced. String getFields(Variable node) { @@ -347,13 +347,13 @@ class SimpleRenderer extends RendererBase { /// rendering various types of Mustache nodes. @immutable class Property { - /// Gets the value of this property on the object [context]. + /// Gets the value of this property on the object `context`. final Object? Function(T context) getValue; final String Function(T, Property, List) renderVariable; /// Gets the bool value (true or false, never null) of this property on the - /// object [context]. + /// object `context`. final bool Function(T context)? getBool; final Iterable Function( diff --git a/pubspec.yaml b/pubspec.yaml index bf6fcb87b1..4f8b7cfe49 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: ^3.2.0 dependencies: - analyzer: ^6.4.1 + analyzer: ^6.5.0 args: ^2.4.1 collection: ^1.17.0 crypto: ^3.0.3 diff --git a/test/mustachio/aot_compiler_builder_test.dart b/test/mustachio/aot_compiler_builder_test.dart index 878230ad59..0d246e4c36 100644 --- a/test/mustachio/aot_compiler_builder_test.dart +++ b/test/mustachio/aot_compiler_builder_test.dart @@ -109,7 +109,7 @@ class Baz {} var fooRenderFunction = renderersLibrary.getTopLevelFunction('renderFoo')!; expect(fooRenderFunction.typeParameters, hasLength(1)); var fBound = fooRenderFunction.typeParameters.single.bound!; - expect(fBound.getDisplayString(withNullability: false), equals('num')); + expect(fBound.getDisplayString(), equals('num')); }); test('deduplicates partials which share context type LUB', () async { diff --git a/test/mustachio/runtime_renderer_builder_test.dart b/test/mustachio/runtime_renderer_builder_test.dart index 37819ad3da..d28a1a3fc0 100644 --- a/test/mustachio/runtime_renderer_builder_test.dart +++ b/test/mustachio/runtime_renderer_builder_test.dart @@ -234,12 +234,12 @@ class Baz {} var fooRenderFunction = renderersLibrary.getTopLevelFunction('renderFoo')!; expect(fooRenderFunction.typeParameters, hasLength(1)); var fBound = fooRenderFunction.typeParameters.single.bound!; - expect(fBound.getDisplayString(withNullability: false), equals('num')); + expect(fBound.getDisplayString(), equals('num')); var fooRendererClass = renderersLibrary.getClass('_Renderer_Foo')!; expect(fooRendererClass.typeParameters, hasLength(1)); var cBound = fooRenderFunction.typeParameters.single.bound!; - expect(cBound.getDisplayString(withNullability: false), equals('num')); + expect(cBound.getDisplayString(), equals('num')); }); group('does not generate a renderer', () { diff --git a/tool/mustachio/codegen_runtime_renderer.dart b/tool/mustachio/codegen_runtime_renderer.dart index 162d11ea3f..780d1da95b 100644 --- a/tool/mustachio/codegen_runtime_renderer.dart +++ b/tool/mustachio/codegen_runtime_renderer.dart @@ -423,8 +423,7 @@ class ${renderer._rendererClassName}${renderer._typeParametersString} if (superclassRendererName != null) { var superMapName = '$superclassRendererName.propertyMap'; var generics = asGenerics([ - ...supertype.typeArguments - .map((e) => e.getDisplayString(withNullability: false)), + ...supertype.typeArguments.map((e) => e.getDisplayString()), _contextTypeVariable ]); _buffer.writeln(' ...$superMapName$generics(),'); @@ -441,8 +440,7 @@ class ${renderer._rendererClassName}${renderer._typeParametersString} if (mixinRendererName != null) { var mixinMapName = '$mixinRendererName.propertyMap'; var generics = asGenerics([ - ...mixin.typeArguments - .map((e) => e.getDisplayString(withNullability: false)), + ...mixin.typeArguments.map((e) => e.getDisplayString()), _contextTypeVariable ]); _buffer.writeln(' ...$mixinMapName$generics(),'); @@ -476,21 +474,25 @@ class ${renderer._rendererClassName}${renderer._typeParametersString} .writeln('getValue: ($_contextTypeVariable c) => c.${property.name},'); var getterName = property.name; - var getterTypeString = getterType.getDisplayString(withNullability: false); + var getterTypeString = + _typeSystem.promoteToNonNull(getterType).getDisplayString(); // Only add a `getProperties` function, which returns the property map for // [getterType], if [getterType] is a renderable type. if (_typeToRendererClassName.containsKey(getterType.element)) { var rendererClassName = _typeToRendererClassName[getterType.element]; _buffer.writeln(''' renderVariable: - ($_contextTypeVariable c, Property<$_contextTypeVariable> self, List remainingNames) { + ($_contextTypeVariable c, + Property<$_contextTypeVariable> self, + List remainingNames) { if (remainingNames.isEmpty) { return self.getValue(c).toString(); } var name = remainingNames.first; var nextProperty = $rendererClassName.propertyMap().getValue(name); return nextProperty.renderVariable( - self.getValue(c) as $getterTypeString, nextProperty, [...remainingNames.skip(1)]); + self.getValue(c) as $getterTypeString, + nextProperty, [...remainingNames.skip(1)]); }, '''); } else { @@ -676,7 +678,7 @@ class _RendererInfo { _contextClass.typeParametersStringWith(extra); String _renderSingleType(DartType tp) { - var displayString = tp.getDisplayString(withNullability: false); + var displayString = tp.getDisplayString(); var nullabilitySuffix = tp.nullabilitySuffix == NullabilitySuffix.question ? '?' : ''; return '$displayString$nullabilitySuffix'; @@ -710,6 +712,7 @@ extension on InterfaceElement { extension on PropertyAccessorElement { // Whether this property should be omitted from the runtime renderer code. bool get shouldBeOmitted { + var variable = variable2; return isPrivate || isStatic || isSetter || @@ -717,6 +720,7 @@ extension on PropertyAccessorElement { hasProtected || hasVisibleForOverriding || hasVisibleForTesting || + variable == null || variable.hasInternal || variable.hasProtected || variable.hasVisibleForOverriding || diff --git a/tool/mustachio/utilities.dart b/tool/mustachio/utilities.dart index 89418ffd72..8852e035d6 100644 --- a/tool/mustachio/utilities.dart +++ b/tool/mustachio/utilities.dart @@ -8,8 +8,7 @@ extension InterfaceElementExtension on InterfaceElement { /// The type parameters, if any, as a String, including bounds and the angled /// brackets, otherwise a blank String. String get typeParametersString { - return asGenerics(typeParameters - .map((tp) => tp.getDisplayString(withNullability: false))); + return asGenerics(typeParameters.map((tp) => tp.getDisplayString())); } /// The type variables, if any, as a String, including the angled brackets, @@ -22,8 +21,7 @@ extension InterfaceElementExtension on InterfaceElement { /// generics. String typeParametersStringWith(String extra) { return asGenerics([ - ...typeParameters - .map((tp) => tp.getDisplayString(withNullability: false)), + ...typeParameters.map((tp) => tp.getDisplayString()), extra, ]); }