From d8fab3228ba1474443237ccf98e6061cf1a2e7e0 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 2 Jun 2026 12:24:36 -0700 Subject: [PATCH] Augment. Support for function-typed formal parameters in augmentations. Change-Id: I665810aaeeb96dceb0045c98d426493a0fc75892 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507960 Reviewed-by: Johnni Winther --- .../lib/src/dart/element/element.dart | 21 +- .../test/src/summary/elements/class_test.dart | 870 ++++++++++++++++++ .../elements/top_level_function_test.dart | 244 +++++ 3 files changed, 1125 insertions(+), 10 deletions(-) diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index a147dbe32fc..049b4432e98 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -3837,17 +3837,18 @@ class FormalParameterElementImpl extends PromotableElementImpl this._firstFragment, { FormalParameterElementImpl? baseFormalParameter, }) : _baseFormalParameter = baseFormalParameter { - FormalParameterFragmentImpl? fragment = _firstFragment; - while (fragment != null) { + for (var fragment in _fragments) { fragment._element = this; - fragment = fragment.nextFragment; - } - - for (var typeParameter in _firstFragment._typeParameters) { - TypeParameterElementImpl(firstFragment: typeParameter); - } - for (var formalParameter in _firstFragment._formalParameters) { - formalParameter.initElement(); + for (var typeParameter in fragment._typeParameters) { + if (typeParameter.previousFragment == null) { + TypeParameterElementImpl(firstFragment: typeParameter); + } + } + for (var formalParameter in fragment._formalParameters) { + if (formalParameter.previousFragment == null) { + formalParameter.initElement(); + } + } } } diff --git a/pkg/analyzer/test/src/summary/elements/class_test.dart b/pkg/analyzer/test/src/summary/elements/class_test.dart index 27e7666e7a4..a54689d98f6 100644 --- a/pkg/analyzer/test/src/summary/elements/class_test.dart +++ b/pkg/analyzer/test/src/summary/elements/class_test.dart @@ -16109,6 +16109,69 @@ library '''); } + test_constructor_secondary_augmentation_chain_formalParameters_rP1__rP1ft() async { + var library = await buildLibrary(r''' +class A { + A.named(void Function(int) p1); +} +augment class A { + augment A.named(void p1(int a)); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + nextFragment: #F2 + constructors + #F3 isOriginDeclaration named (nameOffset:14) (firstTokenOffset:12) (offset:14) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 12 + periodOffset: 13 + formalParameters + #F4 requiredPositional isOriginDeclaration p1 (nameOffset:39) (firstTokenOffset:20) (offset:39) + element: ::@class::A::@constructor::named::@formalParameter::p1 + nextFragment: #F5 + nextFragment: #F6 + #F2 isAugmentation class A (nameOffset:60) (firstTokenOffset:46) (offset:60) + element: ::@class::A + previousFragment: #F1 + constructors + #F6 isAugmentation isOriginDeclaration named (nameOffset:76) (firstTokenOffset:66) (offset:76) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 74 + periodOffset: 75 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:87) (firstTokenOffset:82) (offset:87) + element: ::@class::A::@constructor::named::@formalParameter::p1 + parameters + #F7 requiredPositional isOriginDeclaration a (nameOffset:94) (firstTokenOffset:90) (offset:94) + element: a@94 + previousFragment: #F4 + previousFragment: #F3 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginDeclaration named + reference: ::@class::A::@constructor::named + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F4 + type: void Function(int) +'''); + } + test_constructor_secondary_augmentation_chain_formalParameters_rP1__rP2() async { var library = await buildLibrary(r''' class A { @@ -17222,6 +17285,484 @@ library '''); } + test_constructor_secondary_augmentation_chain_formalParameters_rP1ft__fP1ft() async { + var library = await buildLibrary(r''' +class A { + final void Function(int) p1; + A(void p1(int a)); +} +augment class A { + augment A(void this.p1(int a)); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + nextFragment: #F2 + fields + #F3 isFinal isOriginDeclaration p1 (nameOffset:37) (firstTokenOffset:37) (offset:37) + element: ::@class::A::@field::p1 + inducedGetter: #F4 + constructors + #F5 isOriginDeclaration new (nameOffset:) (firstTokenOffset:43) (offset:43) + element: ::@class::A::@constructor::new + typeName: A + typeNameOffset: 43 + formalParameters + #F6 requiredPositional isOriginDeclaration p1 (nameOffset:50) (firstTokenOffset:45) (offset:50) + element: ::@class::A::@constructor::new::@formalParameter::p1 + parameters + #F7 requiredPositional isOriginDeclaration a (nameOffset:57) (firstTokenOffset:53) (offset:57) + element: a@57 + nextFragment: #F8 + nextFragment: #F9 + getters + #F4 isCompleteDeclaration isOriginVariable p1 (nameOffset:) (firstTokenOffset:) (offset:37) + element: ::@class::A::@getter::p1 + inducingVariable: #F3 + #F2 isAugmentation class A (nameOffset:78) (firstTokenOffset:64) (offset:78) + element: ::@class::A + previousFragment: #F1 + constructors + #F9 isAugmentation isCompleteDeclaration isOriginDeclaration new (nameOffset:) (firstTokenOffset:84) (offset:92) + element: ::@class::A::@constructor::new + typeName: A + typeNameOffset: 92 + formalParameters + #F8 requiredPositional isFinal isOriginDeclaration this.p1 (nameOffset:104) (firstTokenOffset:94) (offset:104) + element: ::@class::A::@constructor::new::@formalParameter::p1 + parameters + #F10 requiredPositional isOriginDeclaration a (nameOffset:111) (firstTokenOffset:107) (offset:111) + element: a@111 + previousFragment: #F6 + previousFragment: #F5 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + fields + isFinal isOriginDeclaration p1 + reference: ::@class::A::@field::p1 + firstFragment: #F3 + type: void Function(int) + getter: ::@class::A::@getter::p1 + constructors + isOriginDeclaration new + reference: ::@class::A::@constructor::new + firstFragment: #F5 + formalParameters + #E0 requiredPositional isFinal this.p1 + firstFragment: #F6 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F7 + type: int + field: ::@class::A::@field::p1 + getters + isOriginVariable p1 + reference: ::@class::A::@getter::p1 + firstFragment: #F4 + returnType: void Function(int) + variable: ::@class::A::@field::p1 +'''); + } + + test_constructor_secondary_augmentation_chain_formalParameters_rP1ft__rP1() async { + var library = await buildLibrary(r''' +class A { + A.named(void p1(int a)); +} +augment class A { + augment A.named(void Function(int) p1); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + nextFragment: #F2 + constructors + #F3 isOriginDeclaration named (nameOffset:14) (firstTokenOffset:12) (offset:14) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 12 + periodOffset: 13 + formalParameters + #F4 requiredPositional isOriginDeclaration p1 (nameOffset:25) (firstTokenOffset:20) (offset:25) + element: ::@class::A::@constructor::named::@formalParameter::p1 + parameters + #F5 requiredPositional isOriginDeclaration a (nameOffset:32) (firstTokenOffset:28) (offset:32) + element: a@32 + nextFragment: #F6 + nextFragment: #F7 + #F2 isAugmentation class A (nameOffset:53) (firstTokenOffset:39) (offset:53) + element: ::@class::A + previousFragment: #F1 + constructors + #F7 isAugmentation isOriginDeclaration named (nameOffset:69) (firstTokenOffset:59) (offset:69) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 67 + periodOffset: 68 + formalParameters + #F6 requiredPositional isOriginDeclaration p1 (nameOffset:94) (firstTokenOffset:75) (offset:94) + element: ::@class::A::@constructor::named::@formalParameter::p1 + previousFragment: #F4 + previousFragment: #F3 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginDeclaration named + reference: ::@class::A::@constructor::named + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F4 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F5 + type: int +'''); + } + + test_constructor_secondary_augmentation_chain_formalParameters_rP1ft__rP1ft() async { + var library = await buildLibrary(r''' +class A { + A.named(void p1(int a)); +} +augment class A { + augment A.named(void p1(int a)); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + nextFragment: #F2 + constructors + #F3 isOriginDeclaration named (nameOffset:14) (firstTokenOffset:12) (offset:14) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 12 + periodOffset: 13 + formalParameters + #F4 requiredPositional isOriginDeclaration p1 (nameOffset:25) (firstTokenOffset:20) (offset:25) + element: ::@class::A::@constructor::named::@formalParameter::p1 + parameters + #F5 requiredPositional isOriginDeclaration a (nameOffset:32) (firstTokenOffset:28) (offset:32) + element: a@32 + nextFragment: #F6 + nextFragment: #F7 + #F2 isAugmentation class A (nameOffset:53) (firstTokenOffset:39) (offset:53) + element: ::@class::A + previousFragment: #F1 + constructors + #F7 isAugmentation isOriginDeclaration named (nameOffset:69) (firstTokenOffset:59) (offset:69) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 67 + periodOffset: 68 + formalParameters + #F6 requiredPositional isOriginDeclaration p1 (nameOffset:80) (firstTokenOffset:75) (offset:80) + element: ::@class::A::@constructor::named::@formalParameter::p1 + parameters + #F8 requiredPositional isOriginDeclaration a (nameOffset:87) (firstTokenOffset:83) (offset:87) + element: a@87 + previousFragment: #F4 + previousFragment: #F3 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginDeclaration named + reference: ::@class::A::@constructor::named + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F4 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F5 + type: int +'''); + } + + test_constructor_secondary_augmentation_chain_formalParameters_rP1ft__rP1ft_differentType() async { + var library = await buildLibrary(r''' +class A { + A.named(void p1(int a)); +} +augment class A { + augment A.named(void p1(double a)); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + nextFragment: #F2 + constructors + #F3 isOriginDeclaration named (nameOffset:14) (firstTokenOffset:12) (offset:14) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 12 + periodOffset: 13 + formalParameters + #F4 requiredPositional isOriginDeclaration p1 (nameOffset:25) (firstTokenOffset:20) (offset:25) + element: ::@class::A::@constructor::named::@formalParameter::p1 + parameters + #F5 requiredPositional isOriginDeclaration a (nameOffset:32) (firstTokenOffset:28) (offset:32) + element: a@32 + nextFragment: #F6 + nextFragment: #F7 + #F2 isAugmentation class A (nameOffset:53) (firstTokenOffset:39) (offset:53) + element: ::@class::A + previousFragment: #F1 + constructors + #F7 isAugmentation isOriginDeclaration named (nameOffset:69) (firstTokenOffset:59) (offset:69) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 67 + periodOffset: 68 + formalParameters + #F6 requiredPositional isOriginDeclaration p1 (nameOffset:80) (firstTokenOffset:75) (offset:80) + element: ::@class::A::@constructor::named::@formalParameter::p1 + parameters + #F8 requiredPositional isOriginDeclaration a (nameOffset:90) (firstTokenOffset:83) (offset:90) + element: a@90 + previousFragment: #F4 + previousFragment: #F3 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginDeclaration named + reference: ::@class::A::@constructor::named + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F4 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F5 + type: int +'''); + } + + test_constructor_secondary_augmentation_chain_formalParameters_rP1ft__sP1ft() async { + var library = await buildLibrary(r''' +class A { + A(void p1(int a)); +} +class B extends A { + B(void p1(int a)); +} +augment class B { + augment B(void super.p1(int a)); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + constructors + #F2 isOriginDeclaration new (nameOffset:) (firstTokenOffset:12) (offset:12) + element: ::@class::A::@constructor::new + typeName: A + typeNameOffset: 12 + formalParameters + #F3 requiredPositional isOriginDeclaration p1 (nameOffset:19) (firstTokenOffset:14) (offset:19) + element: ::@class::A::@constructor::new::@formalParameter::p1 + parameters + #F4 requiredPositional isOriginDeclaration a (nameOffset:26) (firstTokenOffset:22) (offset:26) + element: a@26 + #F5 hasExtendsClause class B (nameOffset:39) (firstTokenOffset:33) (offset:39) + element: ::@class::B + nextFragment: #F6 + constructors + #F7 isOriginDeclaration new (nameOffset:) (firstTokenOffset:55) (offset:55) + element: ::@class::B::@constructor::new + typeName: B + typeNameOffset: 55 + formalParameters + #F8 requiredPositional isOriginDeclaration p1 (nameOffset:62) (firstTokenOffset:57) (offset:62) + element: ::@class::B::@constructor::new::@formalParameter::p1 + parameters + #F9 requiredPositional isOriginDeclaration a (nameOffset:69) (firstTokenOffset:65) (offset:69) + element: a@69 + nextFragment: #F10 + nextFragment: #F11 + #F6 isAugmentation class B (nameOffset:90) (firstTokenOffset:76) (offset:90) + element: ::@class::B + previousFragment: #F5 + constructors + #F11 isAugmentation isCompleteDeclaration isOriginDeclaration new (nameOffset:) (firstTokenOffset:96) (offset:104) + element: ::@class::B::@constructor::new + typeName: B + typeNameOffset: 104 + formalParameters + #F10 requiredPositional isFinal isOriginDeclaration super.p1 (nameOffset:117) (firstTokenOffset:106) (offset:117) + element: ::@class::B::@constructor::new::@formalParameter::p1 + parameters + #F12 requiredPositional isOriginDeclaration a (nameOffset:124) (firstTokenOffset:120) (offset:124) + element: a@124 + previousFragment: #F8 + previousFragment: #F7 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginDeclaration new + reference: ::@class::A::@constructor::new + firstFragment: #F2 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F3 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F4 + type: int + isSimplyBounded class B + reference: ::@class::B + firstFragment: #F5 + supertype: A + constructors + isOriginDeclaration new + reference: ::@class::B::@constructor::new + firstFragment: #F7 + formalParameters + #E2 requiredPositional isFinal super.p1 + firstFragment: #F8 + type: void Function(int) + formalParameters + #E3 requiredPositional a + firstFragment: #F9 + type: int + superConstructorParameter: ::@class::A::@constructor::new::@formalParameter::p1 + superConstructor: ::@class::A::@constructor::new +'''); + } + + test_constructor_secondary_augmentation_chain_formalParameters_rP1ftt__rP1ftt() async { + var library = await buildLibrary(r''' +class A { + A.named(int p1(T a)); +} +augment class A { + augment A.named(int p1(T a)); +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + nextFragment: #F2 + constructors + #F3 isOriginDeclaration named (nameOffset:14) (firstTokenOffset:12) (offset:14) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 12 + periodOffset: 13 + formalParameters + #F4 requiredPositional isOriginDeclaration p1 (nameOffset:24) (firstTokenOffset:20) (offset:24) + element: ::@class::A::@constructor::named::@formalParameter::p1 + typeParameters + #F5 T (nameOffset:27) (firstTokenOffset:27) (offset:27) + element: #E0 T + parameters + #F6 requiredPositional isOriginDeclaration a (nameOffset:32) (firstTokenOffset:30) (offset:32) + element: a@32 + nextFragment: #F7 + nextFragment: #F8 + #F2 isAugmentation class A (nameOffset:53) (firstTokenOffset:39) (offset:53) + element: ::@class::A + previousFragment: #F1 + constructors + #F8 isAugmentation isOriginDeclaration named (nameOffset:69) (firstTokenOffset:59) (offset:69) + element: ::@class::A::@constructor::named + typeName: A + typeNameOffset: 67 + periodOffset: 68 + formalParameters + #F7 requiredPositional isOriginDeclaration p1 (nameOffset:79) (firstTokenOffset:75) (offset:79) + element: ::@class::A::@constructor::named::@formalParameter::p1 + typeParameters + #F9 T (nameOffset:82) (firstTokenOffset:82) (offset:82) + element: #E1 T + parameters + #F10 requiredPositional isOriginDeclaration a (nameOffset:87) (firstTokenOffset:85) (offset:87) + element: a@87 + previousFragment: #F4 + previousFragment: #F3 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginDeclaration named + reference: ::@class::A::@constructor::named + firstFragment: #F3 + formalParameters + #E2 requiredPositional p1 + firstFragment: #F4 + type: int Function(T) + typeParameters + #E0 T + firstFragment: #F5 + formalParameters + #E3 requiredPositional a + firstFragment: #F6 + type: T +'''); + } + test_constructor_secondary_augmentation_chain_formalParameters_rp2_rp1__rp1_rp2() async { var library = await buildLibrary(r''' class A { @@ -39017,6 +39558,65 @@ library '''); } + test_method_augmentation_chain_formalParameters_rP1__rP1ft() async { + var library = await buildLibrary(r''' +class A { + void foo(void Function(int) p1) {} + augment void foo(void p1(int a)) {} +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + constructors + #F2 isOriginImplicitDefault new (nameOffset:) (firstTokenOffset:) (offset:6) + element: ::@class::A::@constructor::new + typeName: A + methods + #F3 isCompleteDeclaration isOriginDeclaration foo (nameOffset:17) (firstTokenOffset:12) (offset:17) + element: ::@class::A::@method::foo + nextFragment: #F4 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:40) (firstTokenOffset:21) (offset:40) + element: ::@class::A::@method::foo::@formalParameter::p1 + nextFragment: #F6 + #F4 isAugmentation isCompleteDeclaration isOriginDeclaration foo (nameOffset:62) (firstTokenOffset:49) (offset:62) + element: ::@class::A::@method::foo + previousFragment: #F3 + formalParameters + #F6 requiredPositional isOriginDeclaration p1 (nameOffset:71) (firstTokenOffset:66) (offset:71) + element: ::@class::A::@method::foo::@formalParameter::p1 + parameters + #F7 requiredPositional isOriginDeclaration a (nameOffset:78) (firstTokenOffset:74) (offset:78) + element: a@78 + previousFragment: #F5 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginImplicitDefault new + reference: ::@class::A::@constructor::new + firstFragment: #F2 + methods + isOriginDeclaration foo + reference: ::@class::A::@method::foo + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F5 + type: void Function(int) + returnType: void +'''); + } + test_method_augmentation_chain_formalParameters_rP1__rP2() async { var library = await buildLibrary(r''' class A { @@ -39683,6 +40283,276 @@ library '''); } + test_method_augmentation_chain_formalParameters_rP1ft__rP1() async { + var library = await buildLibrary(r''' +class A { + void foo(void p1(int a)) {} + augment void foo(void Function(int) p1) {} +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + constructors + #F2 isOriginImplicitDefault new (nameOffset:) (firstTokenOffset:) (offset:6) + element: ::@class::A::@constructor::new + typeName: A + methods + #F3 isCompleteDeclaration isOriginDeclaration foo (nameOffset:17) (firstTokenOffset:12) (offset:17) + element: ::@class::A::@method::foo + nextFragment: #F4 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:26) (firstTokenOffset:21) (offset:26) + element: ::@class::A::@method::foo::@formalParameter::p1 + parameters + #F6 requiredPositional isOriginDeclaration a (nameOffset:33) (firstTokenOffset:29) (offset:33) + element: a@33 + nextFragment: #F7 + #F4 isAugmentation isCompleteDeclaration isOriginDeclaration foo (nameOffset:55) (firstTokenOffset:42) (offset:55) + element: ::@class::A::@method::foo + previousFragment: #F3 + formalParameters + #F7 requiredPositional isOriginDeclaration p1 (nameOffset:78) (firstTokenOffset:59) (offset:78) + element: ::@class::A::@method::foo::@formalParameter::p1 + previousFragment: #F5 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginImplicitDefault new + reference: ::@class::A::@constructor::new + firstFragment: #F2 + methods + isOriginDeclaration foo + reference: ::@class::A::@method::foo + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F5 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F6 + type: int + returnType: void +'''); + } + + test_method_augmentation_chain_formalParameters_rP1ft__rP1ft() async { + var library = await buildLibrary(r''' +class A { + void foo(void p1(int a)) {} + augment void foo(void p1(int a)) {} +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + constructors + #F2 isOriginImplicitDefault new (nameOffset:) (firstTokenOffset:) (offset:6) + element: ::@class::A::@constructor::new + typeName: A + methods + #F3 isCompleteDeclaration isOriginDeclaration foo (nameOffset:17) (firstTokenOffset:12) (offset:17) + element: ::@class::A::@method::foo + nextFragment: #F4 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:26) (firstTokenOffset:21) (offset:26) + element: ::@class::A::@method::foo::@formalParameter::p1 + parameters + #F6 requiredPositional isOriginDeclaration a (nameOffset:33) (firstTokenOffset:29) (offset:33) + element: a@33 + nextFragment: #F7 + #F4 isAugmentation isCompleteDeclaration isOriginDeclaration foo (nameOffset:55) (firstTokenOffset:42) (offset:55) + element: ::@class::A::@method::foo + previousFragment: #F3 + formalParameters + #F7 requiredPositional isOriginDeclaration p1 (nameOffset:64) (firstTokenOffset:59) (offset:64) + element: ::@class::A::@method::foo::@formalParameter::p1 + parameters + #F8 requiredPositional isOriginDeclaration a (nameOffset:71) (firstTokenOffset:67) (offset:71) + element: a@71 + previousFragment: #F5 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginImplicitDefault new + reference: ::@class::A::@constructor::new + firstFragment: #F2 + methods + isOriginDeclaration foo + reference: ::@class::A::@method::foo + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F5 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F6 + type: int + returnType: void +'''); + } + + test_method_augmentation_chain_formalParameters_rP1ft__rP1ft_differentType() async { + var library = await buildLibrary(r''' +class A { + void foo(void p1(int a)) {} + augment void foo(void p1(double a)) {} +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + constructors + #F2 isOriginImplicitDefault new (nameOffset:) (firstTokenOffset:) (offset:6) + element: ::@class::A::@constructor::new + typeName: A + methods + #F3 isCompleteDeclaration isOriginDeclaration foo (nameOffset:17) (firstTokenOffset:12) (offset:17) + element: ::@class::A::@method::foo + nextFragment: #F4 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:26) (firstTokenOffset:21) (offset:26) + element: ::@class::A::@method::foo::@formalParameter::p1 + parameters + #F6 requiredPositional isOriginDeclaration a (nameOffset:33) (firstTokenOffset:29) (offset:33) + element: a@33 + nextFragment: #F7 + #F4 isAugmentation isCompleteDeclaration isOriginDeclaration foo (nameOffset:55) (firstTokenOffset:42) (offset:55) + element: ::@class::A::@method::foo + previousFragment: #F3 + formalParameters + #F7 requiredPositional isOriginDeclaration p1 (nameOffset:64) (firstTokenOffset:59) (offset:64) + element: ::@class::A::@method::foo::@formalParameter::p1 + parameters + #F8 requiredPositional isOriginDeclaration a (nameOffset:74) (firstTokenOffset:67) (offset:74) + element: a@74 + previousFragment: #F5 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginImplicitDefault new + reference: ::@class::A::@constructor::new + firstFragment: #F2 + methods + isOriginDeclaration foo + reference: ::@class::A::@method::foo + firstFragment: #F3 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F5 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F6 + type: int + returnType: void +'''); + } + + test_method_augmentation_chain_formalParameters_rP1ftt__rP1ftt() async { + var library = await buildLibrary(r''' +class A { + void foo(int p1(T a)) {} + augment void foo(int p1(T a)) {} +} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + classes + #F1 class A (nameOffset:6) (firstTokenOffset:0) (offset:6) + element: ::@class::A + constructors + #F2 isOriginImplicitDefault new (nameOffset:) (firstTokenOffset:) (offset:6) + element: ::@class::A::@constructor::new + typeName: A + methods + #F3 isCompleteDeclaration isOriginDeclaration foo (nameOffset:17) (firstTokenOffset:12) (offset:17) + element: ::@class::A::@method::foo + nextFragment: #F4 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:25) (firstTokenOffset:21) (offset:25) + element: ::@class::A::@method::foo::@formalParameter::p1 + typeParameters + #F6 T (nameOffset:28) (firstTokenOffset:28) (offset:28) + element: #E0 T + parameters + #F7 requiredPositional isOriginDeclaration a (nameOffset:33) (firstTokenOffset:31) (offset:33) + element: a@33 + nextFragment: #F8 + #F4 isAugmentation isCompleteDeclaration isOriginDeclaration foo (nameOffset:55) (firstTokenOffset:42) (offset:55) + element: ::@class::A::@method::foo + previousFragment: #F3 + formalParameters + #F8 requiredPositional isOriginDeclaration p1 (nameOffset:63) (firstTokenOffset:59) (offset:63) + element: ::@class::A::@method::foo::@formalParameter::p1 + typeParameters + #F9 T (nameOffset:66) (firstTokenOffset:66) (offset:66) + element: #E1 T + parameters + #F10 requiredPositional isOriginDeclaration a (nameOffset:71) (firstTokenOffset:69) (offset:71) + element: a@71 + previousFragment: #F5 + classes + isSimplyBounded class A + reference: ::@class::A + firstFragment: #F1 + constructors + isOriginImplicitDefault new + reference: ::@class::A::@constructor::new + firstFragment: #F2 + methods + isOriginDeclaration foo + reference: ::@class::A::@method::foo + firstFragment: #F3 + formalParameters + #E2 requiredPositional p1 + firstFragment: #F5 + type: int Function(T) + typeParameters + #E0 T + firstFragment: #F6 + formalParameters + #E3 requiredPositional a + firstFragment: #F7 + type: T + returnType: void +'''); + } + test_method_augmentation_chain_formalParameters_rp2_rp1__rp1_rp2() async { var library = await buildLibrary(r''' class A { diff --git a/pkg/analyzer/test/src/summary/elements/top_level_function_test.dart b/pkg/analyzer/test/src/summary/elements/top_level_function_test.dart index e336ec0656a..1b900706831 100644 --- a/pkg/analyzer/test/src/summary/elements/top_level_function_test.dart +++ b/pkg/analyzer/test/src/summary/elements/top_level_function_test.dart @@ -1104,6 +1104,48 @@ library '''); } + test_formalParameters_rP1__rP1ft() async { + var library = await buildLibrary(r''' +void foo(void Function(int) p1) {} +augment void foo(void p1(int a)) {} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + functions + #F1 isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:5) (firstTokenOffset:0) (offset:5) + element: ::@function::foo + nextFragment: #F2 + formalParameters + #F3 requiredPositional isOriginDeclaration p1 (nameOffset:28) (firstTokenOffset:9) (offset:28) + element: ::@function::foo::@formalParameter::p1 + nextFragment: #F4 + #F2 isAugmentation isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:48) (firstTokenOffset:35) (offset:48) + element: ::@function::foo + previousFragment: #F1 + formalParameters + #F4 requiredPositional isOriginDeclaration p1 (nameOffset:57) (firstTokenOffset:52) (offset:57) + element: ::@function::foo::@formalParameter::p1 + parameters + #F5 requiredPositional isOriginDeclaration a (nameOffset:64) (firstTokenOffset:60) (offset:64) + element: a@64 + previousFragment: #F3 + functions + isOriginDeclaration isStatic foo + reference: ::@function::foo + firstFragment: #F1 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F3 + type: void Function(int) + returnType: void +'''); + } + test_formalParameters_rP1__rP2() async { var library = await buildLibrary(r''' void foo(int p1) {} @@ -1555,6 +1597,208 @@ library '''); } + test_formalParameters_rP1ft__rP1() async { + var library = await buildLibrary(r''' +void foo(void p1(int a)) {} +augment void foo(void Function(int) p1) {} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + functions + #F1 isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:5) (firstTokenOffset:0) (offset:5) + element: ::@function::foo + nextFragment: #F2 + formalParameters + #F3 requiredPositional isOriginDeclaration p1 (nameOffset:14) (firstTokenOffset:9) (offset:14) + element: ::@function::foo::@formalParameter::p1 + parameters + #F4 requiredPositional isOriginDeclaration a (nameOffset:21) (firstTokenOffset:17) (offset:21) + element: a@21 + nextFragment: #F5 + #F2 isAugmentation isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:41) (firstTokenOffset:28) (offset:41) + element: ::@function::foo + previousFragment: #F1 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:64) (firstTokenOffset:45) (offset:64) + element: ::@function::foo::@formalParameter::p1 + previousFragment: #F3 + functions + isOriginDeclaration isStatic foo + reference: ::@function::foo + firstFragment: #F1 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F3 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F4 + type: int + returnType: void +'''); + } + + test_formalParameters_rP1ft__rP1ft() async { + var library = await buildLibrary(r''' +void foo(void p1(int a)) {} +augment void foo(void p1(int a)) {} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + functions + #F1 isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:5) (firstTokenOffset:0) (offset:5) + element: ::@function::foo + nextFragment: #F2 + formalParameters + #F3 requiredPositional isOriginDeclaration p1 (nameOffset:14) (firstTokenOffset:9) (offset:14) + element: ::@function::foo::@formalParameter::p1 + parameters + #F4 requiredPositional isOriginDeclaration a (nameOffset:21) (firstTokenOffset:17) (offset:21) + element: a@21 + nextFragment: #F5 + #F2 isAugmentation isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:41) (firstTokenOffset:28) (offset:41) + element: ::@function::foo + previousFragment: #F1 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:50) (firstTokenOffset:45) (offset:50) + element: ::@function::foo::@formalParameter::p1 + parameters + #F6 requiredPositional isOriginDeclaration a (nameOffset:57) (firstTokenOffset:53) (offset:57) + element: a@57 + previousFragment: #F3 + functions + isOriginDeclaration isStatic foo + reference: ::@function::foo + firstFragment: #F1 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F3 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F4 + type: int + returnType: void +'''); + } + + test_formalParameters_rP1ft__rP1ft_differentType() async { + var library = await buildLibrary(r''' +void foo(void p1(int a)) {} +augment void foo(void p1(double a)) {} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + functions + #F1 isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:5) (firstTokenOffset:0) (offset:5) + element: ::@function::foo + nextFragment: #F2 + formalParameters + #F3 requiredPositional isOriginDeclaration p1 (nameOffset:14) (firstTokenOffset:9) (offset:14) + element: ::@function::foo::@formalParameter::p1 + parameters + #F4 requiredPositional isOriginDeclaration a (nameOffset:21) (firstTokenOffset:17) (offset:21) + element: a@21 + nextFragment: #F5 + #F2 isAugmentation isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:41) (firstTokenOffset:28) (offset:41) + element: ::@function::foo + previousFragment: #F1 + formalParameters + #F5 requiredPositional isOriginDeclaration p1 (nameOffset:50) (firstTokenOffset:45) (offset:50) + element: ::@function::foo::@formalParameter::p1 + parameters + #F6 requiredPositional isOriginDeclaration a (nameOffset:60) (firstTokenOffset:53) (offset:60) + element: a@60 + previousFragment: #F3 + functions + isOriginDeclaration isStatic foo + reference: ::@function::foo + firstFragment: #F1 + formalParameters + #E0 requiredPositional p1 + firstFragment: #F3 + type: void Function(int) + formalParameters + #E1 requiredPositional a + firstFragment: #F4 + type: int + returnType: void +'''); + } + + test_formalParameters_rP1ftt__rP1ftt() async { + var library = await buildLibrary(r''' +void foo(int p1(T a)) {} +augment void foo(int p1(T a)) {} +'''); + + checkElementText(library, r''' +library + reference: + fragments + #F0 + element: + functions + #F1 isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:5) (firstTokenOffset:0) (offset:5) + element: ::@function::foo + nextFragment: #F2 + formalParameters + #F3 requiredPositional isOriginDeclaration p1 (nameOffset:13) (firstTokenOffset:9) (offset:13) + element: ::@function::foo::@formalParameter::p1 + typeParameters + #F4 T (nameOffset:16) (firstTokenOffset:16) (offset:16) + element: #E0 T + parameters + #F5 requiredPositional isOriginDeclaration a (nameOffset:21) (firstTokenOffset:19) (offset:21) + element: a@21 + nextFragment: #F6 + #F2 isAugmentation isCompleteDeclaration isOriginDeclaration isStatic foo (nameOffset:41) (firstTokenOffset:28) (offset:41) + element: ::@function::foo + previousFragment: #F1 + formalParameters + #F6 requiredPositional isOriginDeclaration p1 (nameOffset:49) (firstTokenOffset:45) (offset:49) + element: ::@function::foo::@formalParameter::p1 + typeParameters + #F7 T (nameOffset:52) (firstTokenOffset:52) (offset:52) + element: #E1 T + parameters + #F8 requiredPositional isOriginDeclaration a (nameOffset:57) (firstTokenOffset:55) (offset:57) + element: a@57 + previousFragment: #F3 + functions + isOriginDeclaration isStatic foo + reference: ::@function::foo + firstFragment: #F1 + formalParameters + #E2 requiredPositional p1 + firstFragment: #F3 + type: int Function(T) + typeParameters + #E0 T + firstFragment: #F4 + formalParameters + #E3 requiredPositional a + firstFragment: #F5 + type: T + returnType: void +'''); + } + test_formalParameters_rp2_rp1__rp1_rp2() async { var library = await buildLibrary(r''' void foo([int p2, int p1]) {}