Resolve constructor initializers.
R=brianwilkerson@google.com
Change-Id: I55101108af0e63f23d3af89a3cb23dc5e46e6392
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98877
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 743595d..f3c39fc 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -2470,21 +2470,20 @@
/// Return the constant initializers for this element, which will be empty if
/// there are no initializers, or `null` if there was an error in the source.
List<ConstructorInitializer> get constantInitializers {
- if (_constantInitializers == null) {
-// if (linkedNode != null) {
-// var context = enclosingUnit.linkedContext;
-// return _constantInitializers ??=
-// linkedNode.constructorDeclaration_initializers.map((node) {
-// return context.readNode(node) as ConstructorInitializer;
-// }).toList();
-// }
+ if (_constantInitializers != null) return _constantInitializers;
- if (serializedExecutable != null) {
- _constantInitializers = serializedExecutable.constantInitializers
- .map((i) => _buildConstructorInitializer(i))
- .toList(growable: false);
- }
+ if (linkedNode != null) {
+ return _constantInitializers = linkedContext.getConstructorInitializers(
+ linkedNode,
+ );
}
+
+ if (serializedExecutable != null) {
+ return _constantInitializers = serializedExecutable.constantInitializers
+ .map((i) => _buildConstructorInitializer(i))
+ .toList(growable: false);
+ }
+
return _constantInitializers;
}
@@ -2626,41 +2625,39 @@
@override
ConstructorElement get redirectedConstructor {
- if (_redirectedConstructor == null) {
-// if (linkedNode != null) {
-// var context = enclosingUnit.linkedContext;
-// if (isFactory) {
-// var node = linkedNode.constructorDeclaration_redirectedConstructor;
-// if (node != null) {
-// ConstructorName ast = context.readNode(node);
-// return ast.staticElement;
-// }
-// } else {
-// for (var node in linkedNode.constructorDeclaration_initializers) {
-// if (node.kind == LinkedNodeKind.redirectingConstructorInvocation) {
-// RedirectingConstructorInvocation ast = context.readNode(node);
-// return ast.staticElement;
-// }
-// }
-// }
-// return null;
-// }
+ if (_redirectedConstructor != null) return _redirectedConstructor;
- if (serializedExecutable != null) {
- if (serializedExecutable.isRedirectedConstructor) {
- if (serializedExecutable.isFactory) {
- _redirectedConstructor = enclosingUnit.resynthesizerContext
- .resolveConstructorRef(enclosingElement,
- serializedExecutable.redirectedConstructor);
- } else {
- _redirectedConstructor = enclosingElement.getNamedConstructor(
- serializedExecutable.redirectedConstructorName);
+ if (linkedNode != null) {
+ var context = enclosingUnit.linkedContext;
+ if (isFactory) {
+ var node = context.getConstructorRedirected(linkedNode);
+ return _redirectedConstructor = node?.staticElement;
+ } else {
+ var initializers = context.getConstructorInitializers(linkedNode);
+ for (var initializer in initializers) {
+ if (initializer is RedirectingConstructorInvocation) {
+ return _redirectedConstructor = initializer.staticElement;
}
- } else {
- return null;
}
}
+ return null;
}
+
+ if (serializedExecutable != null) {
+ if (serializedExecutable.isRedirectedConstructor) {
+ if (serializedExecutable.isFactory) {
+ _redirectedConstructor = enclosingUnit.resynthesizerContext
+ .resolveConstructorRef(
+ enclosingElement, serializedExecutable.redirectedConstructor);
+ } else {
+ _redirectedConstructor = enclosingElement.getNamedConstructor(
+ serializedExecutable.redirectedConstructorName);
+ }
+ } else {
+ return null;
+ }
+ }
+
return _redirectedConstructor;
}
diff --git a/pkg/analyzer/lib/src/summary2/builder/source_library_builder.dart b/pkg/analyzer/lib/src/summary2/builder/source_library_builder.dart
index be3a93a..7339358 100644
--- a/pkg/analyzer/lib/src/summary2/builder/source_library_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/builder/source_library_builder.dart
@@ -280,7 +280,7 @@
}
void resolveConstructors() {
- ConstructorInitializerResolver(linker, reference).resolve();
+ ConstructorInitializerResolver(linker, element).resolve();
}
void resolveDefaultValues() {
diff --git a/pkg/analyzer/lib/src/summary2/constructor_initializer_resolver.dart b/pkg/analyzer/lib/src/summary2/constructor_initializer_resolver.dart
index a0cc02e..fbb7919 100644
--- a/pkg/analyzer/lib/src/summary2/constructor_initializer_resolver.dart
+++ b/pkg/analyzer/lib/src/summary2/constructor_initializer_resolver.dart
@@ -3,37 +3,28 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/resolver/scope.dart';
-import 'package:analyzer/src/summary/format.dart';
import 'package:analyzer/src/summary2/ast_resolver.dart';
import 'package:analyzer/src/summary2/link.dart';
-import 'package:analyzer/src/summary2/linked_unit_context.dart';
-import 'package:analyzer/src/summary2/reference.dart';
+import 'package:analyzer/src/summary2/linking_node_scope.dart';
class ConstructorInitializerResolver {
- Linker _linker;
- LibraryElementImpl _libraryElement;
+ final Linker _linker;
+ final LibraryElementImpl _libraryElement;
- Scope _libraryScope;
- Scope _classScope;
-
- LinkedUnitContext _linkedContext;
-
+ ClassElement _classElement;
ConstructorElement _constructorElement;
- LinkedNodeBuilder _constructorNode;
+ ConstructorDeclarationImpl _constructorNode;
AstResolver _astResolver;
- ConstructorInitializerResolver(this._linker, Reference libraryRef) {
- _libraryElement = _linker.elementFactory.elementOfReference(libraryRef);
- _libraryScope = LibraryScope(_libraryElement);
- }
+ ConstructorInitializerResolver(this._linker, this._libraryElement);
void resolve() {
- for (CompilationUnitElementImpl unit in _libraryElement.units) {
- _linkedContext = unit.linkedContext;
+ for (var unit in _libraryElement.units) {
for (var classElement in unit.types) {
- _classScope = ClassScope(_libraryScope, classElement);
+ _classElement = classElement;
for (var constructorElement in classElement.constructors) {
_constructor(constructorElement);
}
@@ -44,70 +35,47 @@
void _constructor(ConstructorElementImpl constructorElement) {
if (constructorElement.isSynthetic) return;
-// _constructorElement = constructorElement;
-// _constructorNode = constructorElement.linkedNode;
-//
-// var functionScope = FunctionScope(_classScope, constructorElement);
-// functionScope.defineParameters();
-//
-// var nameScope = ConstructorInitializerScope(
-// functionScope,
-// constructorElement,
-// );
-//
-// _astResolver = AstResolver(_linker, _libraryElement, nameScope);
-//
-// _initializers();
-// _redirectedConstructor();
+ _constructorElement = constructorElement;
+ _constructorNode = constructorElement.linkedNode;
+
+ var functionScope = LinkingNodeContext.get(_constructorNode).scope;
+ var initializerScope = ConstructorInitializerScope(
+ functionScope,
+ constructorElement,
+ );
+
+ _astResolver = AstResolver(_linker, _libraryElement, initializerScope);
+
+ _initializers();
+ _redirectedConstructor();
}
void _initializers() {
- throw UnimplementedError();
+ var initializers = _constructorNode.initializers;
-// bool isConst = _constructorNode.constructorDeclaration_constKeyword != 0;
-//
-// var initializers = _constructorNode.constructorDeclaration_initializers;
-// var resolvedList = List<LinkedNodeBuilder>();
-// for (var i = 0; i < initializers.length; ++i) {
-// var unresolvedNode = initializers[i];
-//
-// // Keep only initializers of constant constructors; or redirects.
-// if (!isConst &&
-// unresolvedNode.kind !=
-// LinkedNodeKind.redirectingConstructorInvocation) {
-// continue;
-// }
-//
-// var reader = AstBinaryReader(_linkedContext);
-// var unresolvedAst = reader.readNode(unresolvedNode);
-//
-// var resolvedNode = _astResolver.resolve(
-// _linkedContext,
-// unresolvedAst,
-// enclosingClassElement: _constructorElement.enclosingElement,
-// enclosingExecutableElement: _constructorElement,
-// );
-// resolvedList.add(resolvedNode);
-// }
-// _constructorNode.constructorDeclaration_initializers = resolvedList;
+ var isConst = _constructorNode.constKeyword != null;
+ if (!isConst) {
+ initializers.clear();
+ return;
+ }
+
+ for (var initializer in initializers) {
+ _astResolver.resolve(
+ initializer,
+ enclosingClassElement: _classElement,
+ enclosingExecutableElement: _constructorElement,
+ );
+ }
}
void _redirectedConstructor() {
- throw UnimplementedError();
-
-// var redirectedConstructorNode =
-// _constructorNode.constructorDeclaration_redirectedConstructor;
-// if (redirectedConstructorNode == null) return;
-//
-// var reader = AstBinaryReader(_linkedContext);
-// var unresolvedAst = reader.readNode(redirectedConstructorNode);
-// var resolvedNode = _astResolver.resolve(
-// _linkedContext,
-// unresolvedAst,
-// enclosingClassElement: _constructorElement.enclosingElement,
-// enclosingExecutableElement: _constructorElement,
-// );
-// _constructorNode.constructorDeclaration_redirectedConstructor =
-// resolvedNode;
+ var redirected = _constructorNode.redirectedConstructor;
+ if (redirected != null) {
+ _astResolver.resolve(
+ redirected,
+ enclosingClassElement: _classElement,
+ enclosingExecutableElement: _constructorElement,
+ );
+ }
}
}
diff --git a/pkg/analyzer/lib/src/summary2/lazy_ast.dart b/pkg/analyzer/lib/src/summary2/lazy_ast.dart
index d4f01c5..21076aa 100644
--- a/pkg/analyzer/lib/src/summary2/lazy_ast.dart
+++ b/pkg/analyzer/lib/src/summary2/lazy_ast.dart
@@ -267,7 +267,9 @@
bool _hasBody = false;
bool _hasDocumentationComment = false;
bool _hasFormalParameters = false;
+ bool _hasInitializers = false;
bool _hasMetadata = false;
+ bool _hasRedirectedConstructor = false;
LazyConstructorDeclaration(this.data);
@@ -314,6 +316,21 @@
}
}
+ static void readInitializers(
+ AstBinaryReader reader,
+ ConstructorDeclaration node,
+ ) {
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasInitializers) {
+ var dataList = lazy.data.constructorDeclaration_initializers;
+ for (var i = 0; i < dataList.length; ++i) {
+ var data = dataList[i];
+ node.initializers[i] = reader.readNode(data);
+ }
+ lazy._hasInitializers = true;
+ }
+ }
+
static void readMetadata(
AstBinaryReader reader,
ConstructorDeclaration node,
@@ -329,6 +346,19 @@
}
}
+ static void readRedirectedConstructor(
+ AstBinaryReader reader,
+ ConstructorDeclaration node,
+ ) {
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasRedirectedConstructor) {
+ node.redirectedConstructor = reader.readNode(
+ lazy.data.constructorDeclaration_redirectedConstructor,
+ );
+ lazy._hasRedirectedConstructor = true;
+ }
+ }
+
static void setData(ConstructorDeclaration node, LinkedNode data) {
node.setProperty(_key, LazyConstructorDeclaration(data));
}
diff --git a/pkg/analyzer/lib/src/summary2/link.dart b/pkg/analyzer/lib/src/summary2/link.dart
index 989a7f4..1447fb2 100644
--- a/pkg/analyzer/lib/src/summary2/link.dart
+++ b/pkg/analyzer/lib/src/summary2/link.dart
@@ -221,15 +221,15 @@
}
void _resolveConstructors() {
-// for (var library in builders.values) {
-// library.resolveConstructors();
-// }
+ for (var library in builders.values) {
+ library.resolveConstructors();
+ }
}
void _resolveDefaultValues() {
-// for (var library in builders.values) {
-// library.resolveDefaultValues();
-// }
+ for (var library in builders.values) {
+ library.resolveDefaultValues();
+ }
}
void _resolveMetadata() {
diff --git a/pkg/analyzer/lib/src/summary2/linked_unit_context.dart b/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
index 0451be4..4d82d2d 100644
--- a/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
+++ b/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
@@ -116,6 +116,18 @@
return '';
}
+ List<ConstructorInitializer> getConstructorInitializers(
+ ConstructorDeclaration node,
+ ) {
+ LazyConstructorDeclaration.readInitializers(_astReader, node);
+ return node.initializers;
+ }
+
+ ConstructorName getConstructorRedirected(ConstructorDeclaration node) {
+ LazyConstructorDeclaration.readRedirectedConstructor(_astReader, node);
+ return node.redirectedConstructor;
+ }
+
Iterable<ConstructorDeclaration> getConstructors(AstNode node) sync* {
if (node is ClassOrMixinDeclaration) {
var members = _getClassOrMixinMembers(node);
diff --git a/pkg/analyzer/lib/src/summary2/linking_node_scope.dart b/pkg/analyzer/lib/src/summary2/linking_node_scope.dart
new file mode 100644
index 0000000..7617125
--- /dev/null
+++ b/pkg/analyzer/lib/src/summary2/linking_node_scope.dart
@@ -0,0 +1,25 @@
+// 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/ast/ast.dart';
+import 'package:analyzer/src/generated/resolver.dart';
+
+/// This class provides access to [Scope]s corresponding to [AstNode]s.
+class LinkingNodeContext {
+ static const _key = 'linkingNodeContext';
+
+ final Scope scope;
+
+ LinkingNodeContext(AstNode node, this.scope) {
+ node.setProperty(_key, this);
+ }
+
+ static LinkingNodeContext get(AstNode node) {
+ LinkingNodeContext context = node.getProperty(_key);
+ if (context == null) {
+ throw StateError('No context for: $node');
+ }
+ return context;
+ }
+}
diff --git a/pkg/analyzer/lib/src/summary2/reference_resolver.dart b/pkg/analyzer/lib/src/summary2/reference_resolver.dart
index 4d27523e..28bb335 100644
--- a/pkg/analyzer/lib/src/summary2/reference_resolver.dart
+++ b/pkg/analyzer/lib/src/summary2/reference_resolver.dart
@@ -10,30 +10,10 @@
import 'package:analyzer/src/dart/resolver/scope.dart';
import 'package:analyzer/src/summary/idl.dart';
import 'package:analyzer/src/summary2/linked_element_factory.dart';
+import 'package:analyzer/src/summary2/linking_node_scope.dart';
import 'package:analyzer/src/summary2/reference.dart';
import 'package:analyzer/src/summary2/type_builder.dart';
-// TODO(scheglov) This class is not used, not [get] yet.
-class LinkingNodeContext {
- static const _key = 'linkingNodeContext';
-
- final Scope scope;
-
- LinkingNodeContext(this.scope);
-
- static LinkingNodeContext get(AstNode node) {
- LinkingNodeContext context = node.getProperty(_key);
- if (context == null) {
- throw StateError('No context for: $node');
- }
- return context;
- }
-
- static void set(AstNode node, LinkingNodeContext context) {
- node.setProperty(_key, context);
- }
-}
-
//class ReferenceResolver {
// final LinkingBundleContext linkingBundleContext;
// final TypesToBuild typesToBuild;
@@ -564,7 +544,7 @@
node.name.staticElement = element;
scope = new TypeParameterScope(scope, element);
scope = new ClassScope(scope, element);
- LinkingNodeContext.set(node, LinkingNodeContext(scope));
+ LinkingNodeContext(node, scope);
node.typeParameters?.accept(this);
node.extendsClause?.accept(this);
@@ -592,7 +572,7 @@
node.name.staticElement = element;
scope = new TypeParameterScope(scope, element);
scope = new ClassScope(scope, element);
- LinkingNodeContext.set(node, LinkingNodeContext(scope));
+ LinkingNodeContext(node, scope);
node.typeParameters?.accept(this);
node.superclass?.accept(this);
@@ -605,13 +585,32 @@
@override
void visitCompilationUnit(CompilationUnit node) {
- LinkingNodeContext.set(node, LinkingNodeContext(scope));
+ LinkingNodeContext(node, scope);
node.declarations.accept(this);
}
@override
void visitConstructorDeclaration(ConstructorDeclaration node) {
+ var outerScope = scope;
+ var outerReference = reference;
+
+ var name = node.name?.name ?? '';
+ reference = reference.getChild('@constructor').getChild(name);
+
+ var element = ConstructorElementImpl.forLinkedNode(
+ outerReference.element,
+ reference,
+ node,
+ );
+
+ var functionScope = FunctionScope(scope, element);
+ functionScope.defineParameters();
+ LinkingNodeContext(node, functionScope);
+
node.parameters?.accept(this);
+
+ scope = outerScope;
+ reference = outerReference;
}
@override
@@ -662,7 +661,7 @@
);
node.name.staticElement = element;
scope = new FunctionScope(scope, element);
- LinkingNodeContext.set(node, LinkingNodeContext(scope));
+ LinkingNodeContext(node, scope);
node.returnType?.accept(this);
node.functionExpression.accept(this);
@@ -780,7 +779,7 @@
);
node.name.staticElement = element;
scope = new FunctionScope(scope, element);
- LinkingNodeContext.set(node, LinkingNodeContext(scope));
+ LinkingNodeContext(node, scope);
node.returnType?.accept(this);
node.parameters?.accept(this);
diff --git a/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart b/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
index 16c94d1..313fe5d 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
@@ -338,181 +338,42 @@
@override
@failingTest
- test_constructor_initializers_assertInvocation() async {
- await super.test_constructor_initializers_assertInvocation();
- }
-
- @override
- @failingTest
- test_constructor_initializers_assertInvocation_message() async {
- await super.test_constructor_initializers_assertInvocation_message();
- }
-
- @override
- @failingTest
- test_constructor_initializers_field() async {
- await super.test_constructor_initializers_field();
- }
-
- @override
- @failingTest
- test_constructor_initializers_field_notConst() async {
- await super.test_constructor_initializers_field_notConst();
- }
-
- @override
- @failingTest
- test_constructor_initializers_field_withParameter() async {
- await super.test_constructor_initializers_field_withParameter();
- }
-
- @override
- @failingTest
- test_constructor_initializers_superInvocation_named() async {
- await super.test_constructor_initializers_superInvocation_named();
- }
-
- @override
- @failingTest
- test_constructor_initializers_superInvocation_named_underscore() async {
- await super
- .test_constructor_initializers_superInvocation_named_underscore();
- }
-
- @override
- @failingTest
- test_constructor_initializers_superInvocation_namedExpression() async {
- await super.test_constructor_initializers_superInvocation_namedExpression();
- }
-
- @override
- @failingTest
- test_constructor_initializers_superInvocation_unnamed() async {
- await super.test_constructor_initializers_superInvocation_unnamed();
- }
-
- @override
- @failingTest
- test_constructor_initializers_thisInvocation_named() async {
- await super.test_constructor_initializers_thisInvocation_named();
- }
-
- @override
- @failingTest
- test_constructor_initializers_thisInvocation_namedExpression() async {
- await super.test_constructor_initializers_thisInvocation_namedExpression();
- }
-
- @override
- @failingTest
- test_constructor_initializers_thisInvocation_unnamed() async {
- await super.test_constructor_initializers_thisInvocation_unnamed();
- }
-
- @override
- @failingTest
- test_constructor_redirected_factory_named() async {
- await super.test_constructor_redirected_factory_named();
- }
-
- @override
- @failingTest
test_constructor_redirected_factory_named_generic() async {
await super.test_constructor_redirected_factory_named_generic();
}
@override
@failingTest
- test_constructor_redirected_factory_named_imported() async {
- await super.test_constructor_redirected_factory_named_imported();
- }
-
- @override
- @failingTest
test_constructor_redirected_factory_named_imported_generic() async {
await super.test_constructor_redirected_factory_named_imported_generic();
}
@override
@failingTest
- test_constructor_redirected_factory_named_prefixed() async {
- await super.test_constructor_redirected_factory_named_prefixed();
- }
-
- @override
- @failingTest
test_constructor_redirected_factory_named_prefixed_generic() async {
await super.test_constructor_redirected_factory_named_prefixed_generic();
}
@override
@failingTest
- test_constructor_redirected_factory_unnamed() async {
- await super.test_constructor_redirected_factory_unnamed();
- }
-
- @override
- @failingTest
test_constructor_redirected_factory_unnamed_generic() async {
await super.test_constructor_redirected_factory_unnamed_generic();
}
@override
@failingTest
- test_constructor_redirected_factory_unnamed_imported() async {
- await super.test_constructor_redirected_factory_unnamed_imported();
- }
-
- @override
- @failingTest
test_constructor_redirected_factory_unnamed_imported_generic() async {
await super.test_constructor_redirected_factory_unnamed_imported_generic();
}
@override
@failingTest
- test_constructor_redirected_factory_unnamed_prefixed() async {
- await super.test_constructor_redirected_factory_unnamed_prefixed();
- }
-
- @override
- @failingTest
test_constructor_redirected_factory_unnamed_prefixed_generic() async {
await super.test_constructor_redirected_factory_unnamed_prefixed_generic();
}
@override
@failingTest
- test_constructor_redirected_thisInvocation_named() async {
- await super.test_constructor_redirected_thisInvocation_named();
- }
-
- @override
- @failingTest
- test_constructor_redirected_thisInvocation_named_generic() async {
- await super.test_constructor_redirected_thisInvocation_named_generic();
- }
-
- @override
- @failingTest
- test_constructor_redirected_thisInvocation_unnamed() async {
- await super.test_constructor_redirected_thisInvocation_unnamed();
- }
-
- @override
- @failingTest
- test_constructor_redirected_thisInvocation_unnamed_generic() async {
- await super.test_constructor_redirected_thisInvocation_unnamed_generic();
- }
-
- @override
- @failingTest
- test_constructor_withCycles_const() async {
- await super.test_constructor_withCycles_const();
- }
-
- @override
- @failingTest
test_defaultValue_genericFunction() async {
await super.test_defaultValue_genericFunction();
}
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 77b78c1..0bc59334 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -4589,6 +4589,38 @@
test_constructor_redirected_thisInvocation_named() async {
var library = await checkLibrary('''
class C {
+ const C.named();
+ const C() : this.named();
+}
+''');
+ checkElementText(library, r'''
+class C {
+ const C.named();
+ const C() = C.named : this.
+ named/*location: test.dart;C;named*/();
+}
+''');
+ }
+
+ test_constructor_redirected_thisInvocation_named_generic() async {
+ var library = await checkLibrary('''
+class C<T> {
+ const C.named();
+ const C() : this.named();
+}
+''');
+ checkElementText(library, r'''
+class C<T> {
+ const C.named();
+ const C() = C<T>.named : this.
+ named/*location: test.dart;C;named*/();
+}
+''');
+ }
+
+ test_constructor_redirected_thisInvocation_named_notConst() async {
+ var library = await checkLibrary('''
+class C {
C.named();
C() : this.named();
}
@@ -4597,8 +4629,7 @@
checkElementText(library, r'''
class C {
C.named();
- C() = C.named : this.
- named/*location: test.dart;C;named*/();
+ C();
}
''');
} else {
@@ -4611,32 +4642,37 @@
}
}
- test_constructor_redirected_thisInvocation_named_generic() async {
+ test_constructor_redirected_thisInvocation_unnamed() async {
var library = await checkLibrary('''
-class C<T> {
- C.named();
- C() : this.named();
+class C {
+ const C();
+ const C.named() : this();
}
''');
- if (isAstBasedSummary) {
- checkElementText(library, r'''
-class C<T> {
- C.named();
- C() = C<T>.named : this.
- named/*location: test.dart;C;named*/();
+ checkElementText(library, r'''
+class C {
+ const C();
+ const C.named() = C : this();
}
''');
- } else {
- checkElementText(library, r'''
-class C<T> {
- C.named();
- C() = C<T>.named;
-}
-''');
- }
}
- test_constructor_redirected_thisInvocation_unnamed() async {
+ test_constructor_redirected_thisInvocation_unnamed_generic() async {
+ var library = await checkLibrary('''
+class C<T> {
+ const C();
+ const C.named() : this();
+}
+''');
+ checkElementText(library, r'''
+class C<T> {
+ const C();
+ const C.named() = C<T> : this();
+}
+''');
+ }
+
+ test_constructor_redirected_thisInvocation_unnamed_notConst() async {
var library = await checkLibrary('''
class C {
C();
@@ -4647,7 +4683,7 @@
checkElementText(library, r'''
class C {
C();
- C.named() = C : this();
+ C.named();
}
''');
} else {
@@ -4660,30 +4696,6 @@
}
}
- test_constructor_redirected_thisInvocation_unnamed_generic() async {
- var library = await checkLibrary('''
-class C<T> {
- C();
- C.named() : this();
-}
-''');
- if (isAstBasedSummary) {
- checkElementText(library, r'''
-class C<T> {
- C();
- C.named() = C<T> : this();
-}
-''');
- } else {
- checkElementText(library, r'''
-class C<T> {
- C();
- C.named() = C<T>;
-}
-''');
- }
- }
-
test_constructor_withCycles_const() async {
var library = await checkLibrary('''
class C {