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>
This commit is contained in:
Konstantin Shcheglov 2023-08-09 18:44:14 +00:00 committed by Commit Queue
parent a7e20dd2b0
commit 00e30a89ff

View file

@ -714,7 +714,7 @@ InstanceCreationExpression
''');
}
test_extensionType_generic_unnamed() async {
test_extensionType_generic_primary_unnamed() async {
await assertNoErrorsInCode(r'''
extension type A<T>(T it) {}
@ -748,7 +748,43 @@ InstanceCreationExpression
''');
}
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,10 +819,79 @@ InstanceCreationExpression
''');
}
test_extensionType_notGeneric_unnamed() async {
test_extensionType_notGeneric_primary_unnamed() async {
await assertNoErrorsInCode(r'''
extension type A(int 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_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);
}