Extension types. Test InstanceCreationExpression and secondary constructor.
Change-Id: Id9b0ab27f4f851ecb992c15d1b1bfb1742d77b84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319582
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analyzer/test/src/dart/resolution/instance_creation_test.dart b/pkg/analyzer/test/src/dart/resolution/instance_creation_test.dart
index 3a5420a..9c26e87 100644
--- a/pkg/analyzer/test/src/dart/resolution/instance_creation_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/instance_creation_test.dart
@@ -714,7 +714,7 @@
''');
}
- test_extensionType_generic_unnamed() async {
+ test_extensionType_generic_primary_unnamed() async {
await assertNoErrorsInCode(r'''
extension type A<T>(T it) {}
@@ -748,7 +748,43 @@
''');
}
- test_extensionType_notGeneric_named() async {
+ test_extensionType_generic_secondary_unnamed() async {
+ await assertNoErrorsInCode(r'''
+extension type A<T>.named(T it) {
+ A(this.it);
+}
+
+void f() {
+ A(0);
+}
+''');
+
+ final node = findNode.singleInstanceCreationExpression;
+ assertResolvedNodeText(node, r'''
+InstanceCreationExpression
+ constructorName: ConstructorName
+ type: NamedType
+ name: A
+ element: self::@extensionType::A
+ type: A<int>
+ staticElement: ConstructorMember
+ base: self::@extensionType::A::@constructor::new
+ substitution: {T: int}
+ argumentList: ArgumentList
+ leftParenthesis: (
+ arguments
+ IntegerLiteral
+ literal: 0
+ parameter: FieldFormalParameterMember
+ base: self::@extensionType::A::@constructor::new::@parameter::it
+ substitution: {T: int}
+ staticType: int
+ rightParenthesis: )
+ staticType: A<int>
+''');
+ }
+
+ test_extensionType_notGeneric_primary_named() async {
await assertNoErrorsInCode(r'''
extension type A.named(int it) {}
@@ -783,7 +819,7 @@
''');
}
- test_extensionType_notGeneric_unnamed() async {
+ test_extensionType_notGeneric_primary_unnamed() async {
await assertNoErrorsInCode(r'''
extension type A(int it) {}
@@ -813,6 +849,75 @@
''');
}
+ test_extensionType_notGeneric_secondary_named() async {
+ await assertNoErrorsInCode(r'''
+extension type A(int it) {
+ A.named(this.it);
+}
+
+void f() {
+ A.named(0);
+}
+''');
+
+ final node = findNode.singleInstanceCreationExpression;
+ assertResolvedNodeText(node, r'''
+InstanceCreationExpression
+ constructorName: ConstructorName
+ type: NamedType
+ name: A
+ element: self::@extensionType::A
+ type: A
+ period: .
+ name: SimpleIdentifier
+ token: named
+ staticElement: self::@extensionType::A::@constructor::named
+ staticType: null
+ staticElement: self::@extensionType::A::@constructor::named
+ argumentList: ArgumentList
+ leftParenthesis: (
+ arguments
+ IntegerLiteral
+ literal: 0
+ parameter: self::@extensionType::A::@constructor::named::@parameter::it
+ staticType: int
+ rightParenthesis: )
+ staticType: A
+''');
+ }
+
+ test_extensionType_notGeneric_secondary_unnamed() async {
+ await assertNoErrorsInCode(r'''
+extension type A.named(int it) {
+ A(this.it);
+}
+
+void f() {
+ A(0);
+}
+''');
+
+ final node = findNode.singleInstanceCreationExpression;
+ assertResolvedNodeText(node, r'''
+InstanceCreationExpression
+ constructorName: ConstructorName
+ type: NamedType
+ name: A
+ element: self::@extensionType::A
+ type: A
+ staticElement: self::@extensionType::A::@constructor::new
+ argumentList: ArgumentList
+ leftParenthesis: (
+ arguments
+ IntegerLiteral
+ literal: 0
+ parameter: self::@extensionType::A::@constructor::new::@parameter::it
+ staticType: int
+ rightParenthesis: )
+ staticType: A
+''');
+ }
+
test_extensionType_notGeneric_unresolved() async {
await assertErrorsInCode(r'''
extension type A(int it) {}