Skip to content

Commit

Permalink
Extension types. Tests for InstanceCreationExpression.
Browse files Browse the repository at this point in the history
Change-Id: I50e7cfa4cb574c7626a7a3ae0990edcb8e32b37f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318743
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Aug 7, 2023
1 parent 0cd0412 commit 0e32c36
Showing 1 changed file with 137 additions and 0 deletions.
137 changes: 137 additions & 0 deletions pkg/analyzer/test/src/dart/resolution/instance_creation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,143 @@ InstanceCreationExpression
''');
}

test_extensionType_generic_unnamed() async {
await assertNoErrorsInCode(r'''
extension type A<T>(T 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_named() async {
await assertNoErrorsInCode(r'''
extension type A.named(int 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_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_unresolved() async {
await assertErrorsInCode(r'''
extension type A(int it) {}
void f() {
new A.named(0);
}
''', [
error(CompileTimeErrorCode.NEW_WITH_UNDEFINED_CONSTRUCTOR, 48, 5),
]);

final node = findNode.singleInstanceCreationExpression;
assertResolvedNodeText(node, r'''
InstanceCreationExpression
keyword: new
constructorName: ConstructorName
type: NamedType
name: A
element: self::@extensionType::A
type: A
period: .
name: SimpleIdentifier
token: named
staticElement: <null>
staticType: null
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: (
arguments
IntegerLiteral
literal: 0
parameter: <null>
staticType: int
rightParenthesis: )
staticType: A
''');
}

test_importPrefix() async {
await assertErrorsInCode(r'''
import 'dart:math' as prefix;
Expand Down

0 comments on commit 0e32c36

Please sign in to comment.