| // Copyright (c) 2015, 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/analysis/declared_variables.dart'; |
| import 'package:analyzer/dart/analysis/features.dart'; |
| import 'package:analyzer/dart/ast/ast.dart'; |
| import 'package:analyzer/dart/element/element.dart'; |
| import 'package:analyzer/dart/element/type.dart'; |
| import 'package:analyzer/file_system/file_system.dart'; |
| import 'package:analyzer/src/dart/analysis/experiments.dart'; |
| import 'package:analyzer/src/dart/element/element.dart'; |
| import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| import 'package:analyzer/src/generated/source.dart'; |
| import 'package:analyzer/src/source/package_map_resolver.dart'; |
| import 'package:analyzer/src/test_utilities/mock_sdk.dart'; |
| import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart'; |
| import 'package:pub_semver/pub_semver.dart'; |
| import 'package:test/test.dart'; |
| import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| |
| import 'element_text.dart'; |
| |
| /// Abstract base class for resynthesizing and comparing elements. |
| /// |
| /// The return type separator: → |
| abstract class AbstractResynthesizeTest with ResourceProviderMixin { |
| /// The set of features enabled in this test. |
| late FeatureSet featureSet; |
| |
| DeclaredVariables declaredVariables = DeclaredVariables(); |
| late final SourceFactory sourceFactory; |
| late final FolderBasedDartSdk sdk; |
| |
| late String testFile; |
| late Source testSource; |
| Set<Source> otherLibrarySources = <Source>{}; |
| |
| AbstractResynthesizeTest() { |
| var sdkRoot = newFolder('/sdk'); |
| createMockSdk( |
| resourceProvider: resourceProvider, |
| root: sdkRoot, |
| ); |
| sdk = FolderBasedDartSdk(resourceProvider, sdkRoot); |
| |
| sourceFactory = SourceFactory( |
| [ |
| DartUriResolver(sdk), |
| PackageMapUriResolver(resourceProvider, { |
| 'test': [ |
| getFolder('/home/test/lib'), |
| ], |
| }), |
| ResourceUriResolver(resourceProvider), |
| ], |
| ); |
| |
| testFile = convertPath('/test.dart'); |
| } |
| |
| void addLibrary(String uri) { |
| var source = sourceFactory.forUri(uri)!; |
| otherLibrarySources.add(source); |
| } |
| |
| Source addLibrarySource(String filePath, String contents) { |
| var source = addSource(filePath, contents); |
| otherLibrarySources.add(source); |
| return source; |
| } |
| |
| Source addSource(String path, String contents) { |
| var file = newFile(path, content: contents); |
| var fileSource = file.createSource(); |
| var uri = sourceFactory.restoreUri(fileSource)!; |
| return sourceFactory.forUri2(uri)!; |
| } |
| |
| Source addTestSource(String code, [Uri? uri]) { |
| testSource = addSource(testFile, code); |
| return testSource; |
| } |
| |
| Future<LibraryElementImpl> checkLibrary(String text, |
| {bool allowErrors = false}); |
| } |
| |
| class FeatureSets { |
| static final FeatureSet language_2_9 = FeatureSet.fromEnableFlags2( |
| sdkLanguageVersion: Version.parse('2.9.0'), |
| flags: [], |
| ); |
| |
| static final FeatureSet language_2_12 = FeatureSet.fromEnableFlags2( |
| sdkLanguageVersion: Version.parse('2.12.0'), |
| flags: [], |
| ); |
| |
| static final FeatureSet latestWithExperiments = FeatureSet.fromEnableFlags2( |
| sdkLanguageVersion: Version.parse('2.15.0'), |
| flags: [ |
| EnableString.constructor_tearoffs, |
| ], |
| ); |
| } |
| |
| /// Mixin containing test cases exercising summary resynthesis. Intended to be |
| /// applied to a class implementing [AbstractResynthesizeTest]. |
| mixin ResynthesizeTestCases on AbstractResynthesizeTest { |
| test_class_abstract() async { |
| var library = await checkLibrary('abstract class C {}'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| abstract class C @15 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias() async { |
| var library = await checkLibrary(''' |
| class C = D with E, F, G; |
| class D {} |
| class E {} |
| class F {} |
| class G {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias C @6 |
| supertype: D |
| mixins |
| E |
| F |
| G |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @32 |
| constructors |
| synthetic @-1 |
| class E @43 |
| constructors |
| synthetic @-1 |
| class F @54 |
| constructors |
| synthetic @-1 |
| class G @65 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_abstract() async { |
| var library = await checkLibrary(''' |
| abstract class C = D with E; |
| class D {} |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| abstract class alias C @15 |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @35 |
| constructors |
| synthetic @-1 |
| class E @46 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_documented() async { |
| var library = await checkLibrary(''' |
| /** |
| * Docs |
| */ |
| class C = D with E; |
| |
| class D {} |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias C @22 |
| documentationComment: /**\n * Docs\n */ |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @43 |
| constructors |
| synthetic @-1 |
| class E @54 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_documented_tripleSlash() async { |
| var library = await checkLibrary(''' |
| /// aaa |
| /// b |
| /// cc |
| class C = D with E; |
| |
| class D {} |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias C @27 |
| documentationComment: /// aaa\n/// b\n/// cc |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @48 |
| constructors |
| synthetic @-1 |
| class E @59 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_documented_withLeadingNonDocumentation() async { |
| var library = await checkLibrary(''' |
| // Extra comment so doc comment offset != 0 |
| /** |
| * Docs |
| */ |
| class C = D with E; |
| |
| class D {} |
| class E {}'''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias C @66 |
| documentationComment: /**\n * Docs\n */ |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @87 |
| constructors |
| synthetic @-1 |
| class E @98 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_generic() async { |
| var library = await checkLibrary(''' |
| class Z = A with B<int>, C<double>; |
| class A {} |
| class B<B1> {} |
| class C<C1> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias Z @6 |
| supertype: A |
| mixins |
| B<int> |
| C<double> |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::A::@constructor::• |
| superKeyword: super @0 |
| class A @42 |
| constructors |
| synthetic @-1 |
| class B @53 |
| typeParameters |
| covariant B1 @55 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| class C @68 |
| typeParameters |
| covariant C1 @70 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_notSimplyBounded_self() async { |
| var library = await checkLibrary(''' |
| class C<T extends C> = D with E; |
| class D {} |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class alias C @6 |
| typeParameters |
| covariant T @8 |
| bound: C<dynamic> |
| defaultType: dynamic |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @39 |
| constructors |
| synthetic @-1 |
| class E @50 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_notSimplyBounded_simple_no_type_parameter_bound() async { |
| // If no bounds are specified, then the class is simply bounded by syntax |
| // alone, so there is no reason to assign it a slot. |
| var library = await checkLibrary(''' |
| class C<T> = D with E; |
| class D {} |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias C @6 |
| typeParameters |
| covariant T @8 |
| defaultType: dynamic |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @29 |
| constructors |
| synthetic @-1 |
| class E @40 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_notSimplyBounded_simple_non_generic() async { |
| // If no type parameters are specified, then the class is simply bounded, so |
| // there is no reason to assign it a slot. |
| var library = await checkLibrary(''' |
| class C = D with E; |
| class D {} |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias C @6 |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @26 |
| constructors |
| synthetic @-1 |
| class E @37 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_alias_with_const_constructors() async { |
| testFile = convertPath('/home/test/lib/test.dart'); |
| addLibrarySource('/home/test/lib/a.dart', r''' |
| class Base { |
| const Base._priv(); |
| const Base(); |
| const Base.named(); |
| } |
| '''); |
| var library = await checkLibrary(''' |
| import "a.dart"; |
| class M {} |
| class MixinApp = Base with M; |
| '''); |
| checkElementText(library, r''' |
| library |
| imports |
| package:test/a.dart |
| definingUnit |
| classes |
| class M @23 |
| constructors |
| synthetic @-1 |
| class alias MixinApp @34 |
| supertype: Base |
| mixins |
| M |
| constructors |
| synthetic const @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::• |
| superKeyword: super @0 |
| synthetic const named @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: package:test/a.dart::@class::Base::@constructor::named |
| staticType: null |
| token: named @-1 |
| period: . @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::named |
| superKeyword: super @0 |
| '''); |
| } |
| |
| test_class_alias_with_forwarding_constructors() async { |
| testFile = convertPath('/home/test/lib/test.dart'); |
| addLibrarySource('/home/test/lib/a.dart', r''' |
| class Base { |
| bool x = true; |
| Base._priv(); |
| Base(); |
| Base.noArgs(); |
| Base.requiredArg(x); |
| Base.positionalArg([bool x = true]); |
| Base.positionalArg2([this.x = true]); |
| Base.namedArg({int x = 42}); |
| Base.namedArg2({this.x = true}); |
| factory Base.fact() => Base(); |
| factory Base.fact2() = Base.noArgs; |
| } |
| '''); |
| var library = await checkLibrary(''' |
| import "a.dart"; |
| class M {} |
| class MixinApp = Base with M; |
| '''); |
| checkElementText(library, r''' |
| library |
| imports |
| package:test/a.dart |
| definingUnit |
| classes |
| class M @23 |
| constructors |
| synthetic @-1 |
| class alias MixinApp @34 |
| supertype: Base |
| mixins |
| M |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::• |
| superKeyword: super @0 |
| synthetic noArgs @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: package:test/a.dart::@class::Base::@constructor::noArgs |
| staticType: null |
| token: noArgs @-1 |
| period: . @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::noArgs |
| superKeyword: super @0 |
| synthetic requiredArg @-1 |
| parameters |
| requiredPositional x @-1 |
| type: dynamic |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| arguments |
| SimpleIdentifier |
| staticElement: x@-1 |
| staticType: dynamic |
| token: x @-1 |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: package:test/a.dart::@class::Base::@constructor::requiredArg |
| staticType: null |
| token: requiredArg @-1 |
| period: . @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::requiredArg |
| superKeyword: super @0 |
| synthetic positionalArg @-1 |
| parameters |
| optionalPositional x @-1 |
| type: bool |
| constantInitializer |
| BooleanLiteral |
| literal: true @127 |
| staticType: bool |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| arguments |
| SimpleIdentifier |
| staticElement: x@-1 |
| staticType: bool |
| token: x @-1 |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: package:test/a.dart::@class::Base::@constructor::positionalArg |
| staticType: null |
| token: positionalArg @-1 |
| period: . @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::positionalArg |
| superKeyword: super @0 |
| synthetic positionalArg2 @-1 |
| parameters |
| optionalPositional final x @-1 |
| type: bool |
| constantInitializer |
| BooleanLiteral |
| literal: true @167 |
| staticType: bool |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| arguments |
| SimpleIdentifier |
| staticElement: x@-1 |
| staticType: bool |
| token: x @-1 |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: package:test/a.dart::@class::Base::@constructor::positionalArg2 |
| staticType: null |
| token: positionalArg2 @-1 |
| period: . @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::positionalArg2 |
| superKeyword: super @0 |
| synthetic namedArg @-1 |
| parameters |
| optionalNamed x @-1 |
| type: int |
| constantInitializer |
| IntegerLiteral |
| literal: 42 @200 |
| staticType: int |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| arguments |
| SimpleIdentifier |
| staticElement: x@-1 |
| staticType: int |
| token: x @-1 |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: package:test/a.dart::@class::Base::@constructor::namedArg |
| staticType: null |
| token: namedArg @-1 |
| period: . @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::namedArg |
| superKeyword: super @0 |
| synthetic namedArg2 @-1 |
| parameters |
| optionalNamed final x @-1 |
| type: bool |
| constantInitializer |
| BooleanLiteral |
| literal: true @233 |
| staticType: bool |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| arguments |
| SimpleIdentifier |
| staticElement: x@-1 |
| staticType: bool |
| token: x @-1 |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: package:test/a.dart::@class::Base::@constructor::namedArg2 |
| staticType: null |
| token: namedArg2 @-1 |
| period: . @0 |
| staticElement: package:test/a.dart::@class::Base::@constructor::namedArg2 |
| superKeyword: super @0 |
| '''); |
| } |
| |
| test_class_alias_with_forwarding_constructors_type_substitution() async { |
| var library = await checkLibrary(''' |
| class Base<T> { |
| Base.ctor(T t, List<T> l); |
| } |
| class M {} |
| class MixinApp = Base with M; |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class Base @6 |
| typeParameters |
| covariant T @11 |
| defaultType: dynamic |
| constructors |
| ctor @23 |
| periodOffset: 22 |
| nameEnd: 27 |
| parameters |
| requiredPositional t @30 |
| type: T |
| requiredPositional l @41 |
| type: List<T> |
| class M @53 |
| constructors |
| synthetic @-1 |
| class alias MixinApp @64 |
| supertype: Base<dynamic> |
| mixins |
| M |
| constructors |
| synthetic ctor @-1 |
| parameters |
| requiredPositional t @-1 |
| type: dynamic |
| requiredPositional l @-1 |
| type: List<dynamic> |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| arguments |
| SimpleIdentifier |
| staticElement: t@-1 |
| staticType: dynamic |
| token: t @-1 |
| SimpleIdentifier |
| staticElement: l@-1 |
| staticType: List<dynamic> |
| token: l @-1 |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: self::@class::Base::@constructor::ctor |
| staticType: null |
| token: ctor @-1 |
| period: . @0 |
| staticElement: self::@class::Base::@constructor::ctor |
| superKeyword: super @0 |
| '''); |
| } |
| |
| test_class_alias_with_forwarding_constructors_type_substitution_complex() async { |
| var library = await checkLibrary(''' |
| class Base<T> { |
| Base.ctor(T t, List<T> l); |
| } |
| class M {} |
| class MixinApp<U> = Base<List<U>> with M; |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class Base @6 |
| typeParameters |
| covariant T @11 |
| defaultType: dynamic |
| constructors |
| ctor @23 |
| periodOffset: 22 |
| nameEnd: 27 |
| parameters |
| requiredPositional t @30 |
| type: T |
| requiredPositional l @41 |
| type: List<T> |
| class M @53 |
| constructors |
| synthetic @-1 |
| class alias MixinApp @64 |
| typeParameters |
| covariant U @73 |
| defaultType: dynamic |
| supertype: Base<List<U>> |
| mixins |
| M |
| constructors |
| synthetic ctor @-1 |
| parameters |
| requiredPositional t @-1 |
| type: List<U> |
| requiredPositional l @-1 |
| type: List<List<U>> |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| arguments |
| SimpleIdentifier |
| staticElement: t@-1 |
| staticType: List<U> |
| token: t @-1 |
| SimpleIdentifier |
| staticElement: l@-1 |
| staticType: List<List<U>> |
| token: l @-1 |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| constructorName: SimpleIdentifier |
| staticElement: self::@class::Base::@constructor::ctor |
| staticType: null |
| token: ctor @-1 |
| period: . @0 |
| staticElement: self::@class::Base::@constructor::ctor |
| superKeyword: super @0 |
| '''); |
| } |
| |
| test_class_alias_with_mixin_members() async { |
| var library = await checkLibrary(''' |
| class C = D with E; |
| class D {} |
| class E { |
| int get a => null; |
| void set b(int i) {} |
| void f() {} |
| int x; |
| }'''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class alias C @6 |
| supertype: D |
| mixins |
| E |
| constructors |
| synthetic @-1 |
| constantInitializers |
| SuperConstructorInvocation |
| argumentList: ArgumentList |
| leftParenthesis: ( @0 |
| rightParenthesis: ) @0 |
| staticElement: self::@class::D::@constructor::• |
| superKeyword: super @0 |
| class D @26 |
| constructors |
| synthetic @-1 |
| class E @37 |
| fields |
| x @105 |
| type: int |
| synthetic a @-1 |
| type: int |
| synthetic b @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get x @-1 |
| returnType: int |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: int |
| returnType: void |
| get a @51 |
| returnType: int |
| set b @73 |
| parameters |
| requiredPositional i @79 |
| type: int |
| returnType: void |
| methods |
| f @92 |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_const() async { |
| var library = await checkLibrary('class C { const C(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| const @16 |
| '''); |
| } |
| |
| test_class_constructor_const_external() async { |
| var library = await checkLibrary('class C { external const C(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| external const @25 |
| '''); |
| } |
| |
| test_class_constructor_explicit_named() async { |
| var library = await checkLibrary('class C { C.foo(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| foo @12 |
| periodOffset: 11 |
| nameEnd: 15 |
| '''); |
| } |
| |
| test_class_constructor_explicit_type_params() async { |
| var library = await checkLibrary('class C<T, U> { C(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| defaultType: dynamic |
| covariant U @11 |
| defaultType: dynamic |
| constructors |
| @16 |
| '''); |
| } |
| |
| test_class_constructor_explicit_unnamed() async { |
| var library = await checkLibrary('class C { C(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| @10 |
| '''); |
| } |
| |
| test_class_constructor_external() async { |
| var library = await checkLibrary('class C { external C(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| external @19 |
| '''); |
| } |
| |
| test_class_constructor_factory() async { |
| var library = await checkLibrary('class C { factory C() => throw 0; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| factory @18 |
| '''); |
| } |
| |
| test_class_constructor_field_formal_dynamic_dynamic() async { |
| var library = |
| await checkLibrary('class C { dynamic x; C(dynamic this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @18 |
| type: dynamic |
| constructors |
| @21 |
| parameters |
| requiredPositional final this.x @36 |
| type: dynamic |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_dynamic_typed() async { |
| var library = await checkLibrary('class C { dynamic x; C(int this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @18 |
| type: dynamic |
| constructors |
| @21 |
| parameters |
| requiredPositional final this.x @32 |
| type: int |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_dynamic_untyped() async { |
| var library = await checkLibrary('class C { dynamic x; C(this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @18 |
| type: dynamic |
| constructors |
| @21 |
| parameters |
| requiredPositional final this.x @28 |
| type: dynamic |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_functionTyped_noReturnType() async { |
| var library = await checkLibrary(r''' |
| class C { |
| var x; |
| C(this.x(double b)); |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @16 |
| type: dynamic |
| constructors |
| @21 |
| parameters |
| requiredPositional final this.x @28 |
| type: dynamic Function(double) |
| parameters |
| requiredPositional b @37 |
| type: double |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_functionTyped_withReturnType() async { |
| var library = await checkLibrary(r''' |
| class C { |
| var x; |
| C(int this.x(double b)); |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @16 |
| type: dynamic |
| constructors |
| @21 |
| parameters |
| requiredPositional final this.x @32 |
| type: int Function(double) |
| parameters |
| requiredPositional b @41 |
| type: double |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_functionTyped_withReturnType_generic() async { |
| var library = await checkLibrary(r''' |
| class C { |
| Function() f; |
| C(List<U> this.f<T, U>(T t)); |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| f @23 |
| type: dynamic Function() |
| constructors |
| @28 |
| parameters |
| requiredPositional final this.f @43 |
| type: List<U> Function<T, U>(T) |
| typeParameters |
| covariant T @45 |
| covariant U @48 |
| parameters |
| requiredPositional t @53 |
| type: T |
| accessors |
| synthetic get f @-1 |
| returnType: dynamic Function() |
| synthetic set f @-1 |
| parameters |
| requiredPositional _f @-1 |
| type: dynamic Function() |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_multiple_matching_fields() async { |
| // This is a compile-time error but it should still analyze consistently. |
| var library = await checkLibrary('class C { C(this.x); int x; String x; }', |
| allowErrors: true); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @25 |
| type: int |
| x @35 |
| type: String |
| constructors |
| @10 |
| parameters |
| requiredPositional final this.x @17 |
| type: int |
| accessors |
| synthetic get x @-1 |
| returnType: int |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: int |
| returnType: void |
| synthetic get x @-1 |
| returnType: String |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: String |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_no_matching_field() async { |
| // This is a compile-time error but it should still analyze consistently. |
| var library = |
| await checkLibrary('class C { C(this.x); }', allowErrors: true); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| @10 |
| parameters |
| requiredPositional final this.x @17 |
| type: dynamic |
| '''); |
| } |
| |
| test_class_constructor_field_formal_typed_dynamic() async { |
| var library = await checkLibrary('class C { num x; C(dynamic this.x); }', |
| allowErrors: true); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: num |
| constructors |
| @17 |
| parameters |
| requiredPositional final this.x @32 |
| type: dynamic |
| accessors |
| synthetic get x @-1 |
| returnType: num |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: num |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_typed_typed() async { |
| var library = await checkLibrary('class C { num x; C(int this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: num |
| constructors |
| @17 |
| parameters |
| requiredPositional final this.x @28 |
| type: int |
| accessors |
| synthetic get x @-1 |
| returnType: num |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: num |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_typed_untyped() async { |
| var library = await checkLibrary('class C { num x; C(this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: num |
| constructors |
| @17 |
| parameters |
| requiredPositional final this.x @24 |
| type: num |
| accessors |
| synthetic get x @-1 |
| returnType: num |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: num |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_untyped_dynamic() async { |
| var library = await checkLibrary('class C { var x; C(dynamic this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: dynamic |
| constructors |
| @17 |
| parameters |
| requiredPositional final this.x @32 |
| type: dynamic |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_untyped_typed() async { |
| var library = await checkLibrary('class C { var x; C(int this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: dynamic |
| constructors |
| @17 |
| parameters |
| requiredPositional final this.x @28 |
| type: int |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_field_formal_untyped_untyped() async { |
| var library = await checkLibrary('class C { var x; C(this.x); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: dynamic |
| constructors |
| @17 |
| parameters |
| requiredPositional final this.x @24 |
| type: dynamic |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_fieldFormal_named_noDefault() async { |
| var library = await checkLibrary('class C { int x; C({this.x}); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: int |
| constructors |
| @17 |
| parameters |
| optionalNamed final this.x @25 |
| type: int |
| accessors |
| synthetic get x @-1 |
| returnType: int |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_fieldFormal_named_withDefault() async { |
| var library = await checkLibrary('class C { int x; C({this.x: 42}); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: int |
| constructors |
| @17 |
| parameters |
| optionalNamed final this.x @25 |
| type: int |
| constantInitializer |
| IntegerLiteral |
| literal: 42 @28 |
| staticType: int |
| accessors |
| synthetic get x @-1 |
| returnType: int |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_fieldFormal_optional_noDefault() async { |
| var library = await checkLibrary('class C { int x; C([this.x]); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: int |
| constructors |
| @17 |
| parameters |
| optionalPositional final this.x @25 |
| type: int |
| accessors |
| synthetic get x @-1 |
| returnType: int |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_fieldFormal_optional_withDefault() async { |
| var library = await checkLibrary('class C { int x; C([this.x = 42]); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: int |
| constructors |
| @17 |
| parameters |
| optionalPositional final this.x @25 |
| type: int |
| constantInitializer |
| IntegerLiteral |
| literal: 42 @29 |
| staticType: int |
| accessors |
| synthetic get x @-1 |
| returnType: int |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_constructor_implicit_type_params() async { |
| var library = await checkLibrary('class C<T, U> {}'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| defaultType: dynamic |
| covariant U @11 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_constructor_params() async { |
| var library = await checkLibrary('class C { C(x, int y); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| @10 |
| parameters |
| requiredPositional x @12 |
| type: dynamic |
| requiredPositional y @19 |
| type: int |
| '''); |
| } |
| |
| test_class_constructor_unnamed_implicit() async { |
| var library = await checkLibrary('class C {}'); |
| checkElementText( |
| library, |
| r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| displayName: C |
| ''', |
| withDisplayName: true); |
| } |
| |
| test_class_constructors_named() async { |
| var library = await checkLibrary(''' |
| class C { |
| C.foo(); |
| } |
| '''); |
| checkElementText( |
| library, |
| r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| foo @14 |
| displayName: C.foo |
| periodOffset: 13 |
| nameEnd: 17 |
| ''', |
| withDisplayName: true); |
| } |
| |
| test_class_constructors_unnamed() async { |
| var library = await checkLibrary(''' |
| class C { |
| C(); |
| } |
| '''); |
| checkElementText( |
| library, |
| r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| @12 |
| displayName: C |
| ''', |
| withDisplayName: true); |
| } |
| |
| test_class_constructors_unnamed_new() async { |
| var library = await checkLibrary(''' |
| class C { |
| C.new(); |
| } |
| '''); |
| checkElementText( |
| library, |
| r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| @14 |
| displayName: C |
| periodOffset: 13 |
| nameEnd: 17 |
| ''', |
| withDisplayName: true); |
| } |
| |
| test_class_documented() async { |
| var library = await checkLibrary(''' |
| /** |
| * Docs |
| */ |
| class C {}'''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @22 |
| documentationComment: /**\n * Docs\n */ |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_documented_mix() async { |
| var library = await checkLibrary(''' |
| /** |
| * aaa |
| */ |
| /** |
| * bbb |
| */ |
| class A {} |
| |
| /** |
| * aaa |
| */ |
| /// bbb |
| /// ccc |
| class B {} |
| |
| /// aaa |
| /// bbb |
| /** |
| * ccc |
| */ |
| class C {} |
| |
| /// aaa |
| /// bbb |
| /** |
| * ccc |
| */ |
| /// ddd |
| class D {} |
| |
| /** |
| * aaa |
| */ |
| // bbb |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class A @36 |
| documentationComment: /**\n * bbb\n */ |
| constructors |
| synthetic @-1 |
| class B @79 |
| documentationComment: /// bbb\n/// ccc |
| constructors |
| synthetic @-1 |
| class C @122 |
| documentationComment: /**\n * ccc\n */ |
| constructors |
| synthetic @-1 |
| class D @173 |
| documentationComment: /// ddd |
| constructors |
| synthetic @-1 |
| class E @207 |
| documentationComment: /**\n * aaa\n */ |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_documented_tripleSlash() async { |
| var library = await checkLibrary(''' |
| /// first |
| /// second |
| /// third |
| class C {}'''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @37 |
| documentationComment: /// first\n/// second\n/// third |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_documented_with_references() async { |
| var library = await checkLibrary(''' |
| /** |
| * Docs referring to [D] and [E] |
| */ |
| class C {} |
| |
| class D {} |
| class E {}'''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @47 |
| documentationComment: /**\n * Docs referring to [D] and [E]\n */ |
| constructors |
| synthetic @-1 |
| class D @59 |
| constructors |
| synthetic @-1 |
| class E @70 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_documented_with_windows_line_endings() async { |
| var library = await checkLibrary('/**\r\n * Docs\r\n */\r\nclass C {}'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @25 |
| documentationComment: /**\n * Docs\n */ |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_documented_withLeadingNotDocumentation() async { |
| var library = await checkLibrary(''' |
| // Extra comment so doc comment offset != 0 |
| /** |
| * Docs |
| */ |
| class C {}'''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @66 |
| documentationComment: /**\n * Docs\n */ |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_documented_withMetadata() async { |
| var library = await checkLibrary(''' |
| /// Comment 1 |
| /// Comment 2 |
| @Annotation() |
| class BeforeMeta {} |
| |
| /// Comment 1 |
| /// Comment 2 |
| @Annotation.named() |
| class BeforeMetaNamed {} |
| |
| @Annotation() |
| /// Comment 1 |
| /// Comment 2 |
| class AfterMeta {} |
| |
| /// Comment 1 |
| @Annotation() |
| /// Comment 2 |
| class AroundMeta {} |
| |
| /// Doc comment. |
| @Annotation() |
| // Not doc comment. |
| class DocBeforeMetaNotDocAfter {} |
| |
| class Annotation { |
| const Annotation(); |
| const Annotation.named(); |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class BeforeMeta @48 |
| documentationComment: /// Comment 1\n/// Comment 2 |
| metadata |
| Annotation |
| arguments: ArgumentList |
| leftParenthesis: ( @39 |
| rightParenthesis: ) @40 |
| atSign: @ @28 |
| element: self::@class::Annotation::@constructor::• |
| name: SimpleIdentifier |
| staticElement: self::@class::Annotation |
| staticType: null |
| token: Annotation @29 |
| constructors |
| synthetic @-1 |
| class BeforeMetaNamed @117 |
| documentationComment: /// Comment 1\n/// Comment 2 |
| metadata |
| Annotation |
| arguments: ArgumentList |
| leftParenthesis: ( @108 |
| rightParenthesis: ) @109 |
| atSign: @ @91 |
| element: self::@class::Annotation::@constructor::named |
| name: PrefixedIdentifier |
| identifier: SimpleIdentifier |
| staticElement: self::@class::Annotation::@constructor::named |
| staticType: null |
| token: named @103 |
| period: . @102 |
| prefix: SimpleIdentifier |
| staticElement: self::@class::Annotation |
| staticType: null |
| token: Annotation @92 |
| staticElement: self::@class::Annotation::@constructor::named |
| staticType: null |
| constructors |
| synthetic @-1 |
| class AfterMeta @185 |
| documentationComment: /// Comment 1\n/// Comment 2 |
| metadata |
| Annotation |
| arguments: ArgumentList |
| leftParenthesis: ( @148 |
| rightParenthesis: ) @149 |
| atSign: @ @137 |
| element: self::@class::Annotation::@constructor::• |
| name: SimpleIdentifier |
| staticElement: self::@class::Annotation |
| staticType: null |
| token: Annotation @138 |
| constructors |
| synthetic @-1 |
| class AroundMeta @247 |
| documentationComment: /// Comment 2 |
| metadata |
| Annotation |
| arguments: ArgumentList |
| leftParenthesis: ( @224 |
| rightParenthesis: ) @225 |
| atSign: @ @213 |
| element: self::@class::Annotation::@constructor::• |
| name: SimpleIdentifier |
| staticElement: self::@class::Annotation |
| staticType: null |
| token: Annotation @214 |
| constructors |
| synthetic @-1 |
| class DocBeforeMetaNotDocAfter @319 |
| documentationComment: /// Doc comment. |
| metadata |
| Annotation |
| arguments: ArgumentList |
| leftParenthesis: ( @290 |
| rightParenthesis: ) @291 |
| atSign: @ @279 |
| element: self::@class::Annotation::@constructor::• |
| name: SimpleIdentifier |
| staticElement: self::@class::Annotation |
| staticType: null |
| token: Annotation @280 |
| constructors |
| synthetic @-1 |
| class Annotation @354 |
| constructors |
| const @375 |
| const named @408 |
| periodOffset: 407 |
| nameEnd: 413 |
| '''); |
| } |
| |
| test_class_field_const() async { |
| var library = await checkLibrary('class C { static const int i = 0; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| static const i @27 |
| type: int |
| constantInitializer |
| IntegerLiteral |
| literal: 0 @31 |
| staticType: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic static get i @-1 |
| returnType: int |
| '''); |
| } |
| |
| test_class_field_const_late() async { |
| var library = |
| await checkLibrary('class C { static late const int i = 0; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| static late const i @32 |
| type: int |
| constantInitializer |
| IntegerLiteral |
| literal: 0 @36 |
| staticType: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic static get i @-1 |
| returnType: int |
| '''); |
| } |
| |
| test_class_field_final_withSetter() async { |
| var library = await checkLibrary(r''' |
| class A { |
| final int foo; |
| A(this.foo); |
| set foo(int newValue) {} |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class A @6 |
| fields |
| final foo @22 |
| type: int |
| constructors |
| @29 |
| parameters |
| requiredPositional final this.foo @36 |
| type: int |
| accessors |
| synthetic get foo @-1 |
| returnType: int |
| set foo @48 |
| parameters |
| requiredPositional newValue @56 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_field_implicit_type() async { |
| var library = await checkLibrary('class C { var x; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| x @14 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_field_implicit_type_late() async { |
| var library = await checkLibrary('class C { late var x; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| late x @19 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get x @-1 |
| returnType: dynamic |
| synthetic set x @-1 |
| parameters |
| requiredPositional _x @-1 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_field_inheritedContextType_double() async { |
| var library = await checkLibrary(''' |
| abstract class A { |
| const A(); |
| double get foo; |
| } |
| class B extends A { |
| const B(); |
| final foo = 2; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| abstract class A @15 |
| fields |
| synthetic foo @-1 |
| type: double |
| constructors |
| const @27 |
| accessors |
| abstract get foo @45 |
| returnType: double |
| class B @58 |
| supertype: A |
| fields |
| final foo @93 |
| type: double |
| constantInitializer |
| IntegerLiteral |
| literal: 2 @99 |
| staticType: double |
| constructors |
| const @80 |
| accessors |
| synthetic get foo @-1 |
| returnType: double |
| '''); |
| } |
| |
| test_class_field_static() async { |
| var library = await checkLibrary('class C { static int i; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| static i @21 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic static get i @-1 |
| returnType: int |
| synthetic static set i @-1 |
| parameters |
| requiredPositional _i @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_field_static_final_hasConstConstructor() async { |
| var library = await checkLibrary(''' |
| class C { |
| static final f = 0; |
| const C(); |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| static final f @25 |
| type: int |
| constructors |
| const @40 |
| accessors |
| synthetic static get f @-1 |
| returnType: int |
| '''); |
| } |
| |
| test_class_field_static_late() async { |
| var library = await checkLibrary('class C { static late int i; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| static late i @26 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic static get i @-1 |
| returnType: int |
| synthetic static set i @-1 |
| parameters |
| requiredPositional _i @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_fields() async { |
| var library = await checkLibrary('class C { int i; int j; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| i @14 |
| type: int |
| j @21 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get i @-1 |
| returnType: int |
| synthetic set i @-1 |
| parameters |
| requiredPositional _i @-1 |
| type: int |
| returnType: void |
| synthetic get j @-1 |
| returnType: int |
| synthetic set j @-1 |
| parameters |
| requiredPositional _j @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_fields_late() async { |
| var library = await checkLibrary(''' |
| class C { |
| late int foo; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| late foo @21 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get foo @-1 |
| returnType: int |
| synthetic set foo @-1 |
| parameters |
| requiredPositional _foo @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_fields_late_final() async { |
| var library = await checkLibrary(''' |
| class C { |
| late final int foo; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| late final foo @27 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get foo @-1 |
| returnType: int |
| synthetic set foo @-1 |
| parameters |
| requiredPositional _foo @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_fields_late_final_initialized() async { |
| var library = await checkLibrary(''' |
| class C { |
| late final int foo = 0; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| late final foo @27 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get foo @-1 |
| returnType: int |
| '''); |
| } |
| |
| test_class_fields_late_inference_usingSuper_methodInvocation() async { |
| var library = await checkLibrary(''' |
| class A { |
| int foo() => 0; |
| } |
| |
| class B extends A { |
| late var f = super.foo(); |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class A @6 |
| constructors |
| synthetic @-1 |
| methods |
| foo @16 |
| returnType: int |
| class B @37 |
| supertype: A |
| fields |
| late f @62 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get f @-1 |
| returnType: int |
| synthetic set f @-1 |
| parameters |
| requiredPositional _f @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_fields_late_inference_usingSuper_propertyAccess() async { |
| var library = await checkLibrary(''' |
| class A { |
| int get foo => 0; |
| } |
| |
| class B extends A { |
| late var f = super.foo; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class A @6 |
| fields |
| synthetic foo @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| get foo @20 |
| returnType: int |
| class B @39 |
| supertype: A |
| fields |
| late f @64 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| synthetic get f @-1 |
| returnType: int |
| synthetic set f @-1 |
| parameters |
| requiredPositional _f @-1 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_getter_abstract() async { |
| var library = await checkLibrary('abstract class C { int get x; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| abstract class C @15 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| abstract get x @27 |
| returnType: int |
| '''); |
| } |
| |
| test_class_getter_external() async { |
| var library = await checkLibrary('class C { external int get x; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| external get x @27 |
| returnType: int |
| '''); |
| } |
| |
| test_class_getter_implicit_return_type() async { |
| var library = await checkLibrary('class C { get x => null; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| get x @14 |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_getter_native() async { |
| var library = await checkLibrary(''' |
| class C { |
| int get x() native; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| external get x @20 |
| returnType: int |
| '''); |
| } |
| |
| test_class_getter_static() async { |
| var library = await checkLibrary('class C { static int get x => null; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic static x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| static get x @25 |
| returnType: int |
| '''); |
| } |
| |
| test_class_getters() async { |
| var library = |
| await checkLibrary('class C { int get x => null; get y => null; }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| synthetic y @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| get x @18 |
| returnType: int |
| get y @33 |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_implicitField_getterFirst() async { |
| var library = await checkLibrary(''' |
| class C { |
| int get x => 0; |
| void set x(int value) {} |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| get x @20 |
| returnType: int |
| set x @39 |
| parameters |
| requiredPositional value @45 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_implicitField_setterFirst() async { |
| var library = await checkLibrary(''' |
| class C { |
| void set x(int value) {} |
| int get x => 0; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| set x @21 |
| parameters |
| requiredPositional value @27 |
| type: int |
| returnType: void |
| get x @47 |
| returnType: int |
| '''); |
| } |
| |
| test_class_interfaces() async { |
| var library = await checkLibrary(''' |
| class C implements D, E {} |
| class D {} |
| class E {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| interfaces |
| D |
| E |
| constructors |
| synthetic @-1 |
| class D @33 |
| constructors |
| synthetic @-1 |
| class E @44 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_interfaces_Function() async { |
| var library = await checkLibrary(''' |
| class A {} |
| class B {} |
| class C implements A, Function, B {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class A @6 |
| constructors |
| synthetic @-1 |
| class B @17 |
| constructors |
| synthetic @-1 |
| class C @28 |
| interfaces |
| A |
| B |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_interfaces_unresolved() async { |
| var library = await checkLibrary( |
| 'class C implements X, Y, Z {} class X {} class Z {}', |
| allowErrors: true); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| interfaces |
| X |
| Z |
| constructors |
| synthetic @-1 |
| class X @36 |
| constructors |
| synthetic @-1 |
| class Z @47 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_method_abstract() async { |
| var library = await checkLibrary('abstract class C { f(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| abstract class C @15 |
| constructors |
| synthetic @-1 |
| methods |
| abstract f @19 |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_method_external() async { |
| var library = await checkLibrary('class C { external f(); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| methods |
| external f @19 |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_method_namedAsSupertype() async { |
| var library = await checkLibrary(r''' |
| class A {} |
| class B extends A { |
| void A() {} |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class A @6 |
| constructors |
| synthetic @-1 |
| class B @17 |
| supertype: A |
| constructors |
| synthetic @-1 |
| methods |
| A @38 |
| returnType: void |
| '''); |
| } |
| |
| test_class_method_native() async { |
| var library = await checkLibrary(''' |
| class C { |
| int m() native; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| methods |
| external m @16 |
| returnType: int |
| '''); |
| } |
| |
| test_class_method_params() async { |
| var library = await checkLibrary('class C { f(x, y) {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| methods |
| f @10 |
| parameters |
| requiredPositional x @12 |
| type: dynamic |
| requiredPositional y @15 |
| type: dynamic |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_method_static() async { |
| var library = await checkLibrary('class C { static f() {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| methods |
| static f @17 |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_methods() async { |
| var library = await checkLibrary('class C { f() {} g() {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| methods |
| f @10 |
| returnType: dynamic |
| g @17 |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_mixins() async { |
| var library = await checkLibrary(''' |
| class C extends D with E, F, G {} |
| class D {} |
| class E {} |
| class F {} |
| class G {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| supertype: D |
| mixins |
| E |
| F |
| G |
| constructors |
| synthetic @-1 |
| class D @40 |
| constructors |
| synthetic @-1 |
| class E @51 |
| constructors |
| synthetic @-1 |
| class F @62 |
| constructors |
| synthetic @-1 |
| class G @73 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_mixins_generic() async { |
| var library = await checkLibrary(''' |
| class Z extends A with B<int>, C<double> {} |
| class A {} |
| class B<B1> {} |
| class C<C1> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class Z @6 |
| supertype: A |
| mixins |
| B<int> |
| C<double> |
| constructors |
| synthetic @-1 |
| class A @50 |
| constructors |
| synthetic @-1 |
| class B @61 |
| typeParameters |
| covariant B1 @63 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| class C @76 |
| typeParameters |
| covariant C1 @78 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_mixins_unresolved() async { |
| var library = await checkLibrary( |
| 'class C extends Object with X, Y, Z {} class X {} class Z {}', |
| allowErrors: true); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| supertype: Object |
| mixins |
| X |
| Z |
| constructors |
| synthetic @-1 |
| class X @45 |
| constructors |
| synthetic @-1 |
| class Z @56 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_circularity_via_typedef() async { |
| // C's type parameter T is not simply bounded because its bound, F, expands |
| // to `dynamic F(C)`, which refers to C. |
| var library = await checkLibrary(''' |
| class C<T extends F> {} |
| typedef F(C value); |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: dynamic |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| typeAliases |
| functionTypeAliasBased notSimplyBounded F @32 |
| aliasedType: dynamic Function(C<dynamic>) |
| aliasedElement: GenericFunctionTypeElement |
| parameters |
| requiredPositional value @36 |
| type: C<dynamic> |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_notSimplyBounded_circularity_with_type_params() async { |
| // C's type parameter T is simply bounded because even though it refers to |
| // C, it specifies a bound. |
| var library = await checkLibrary(''' |
| class C<T extends C<dynamic>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| bound: C<dynamic> |
| defaultType: C<dynamic> |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_complex_by_cycle_class() async { |
| var library = await checkLibrary(''' |
| class C<T extends D> {} |
| class D<T extends C> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: D<dynamic> |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| notSimplyBounded class D @30 |
| typeParameters |
| covariant T @32 |
| bound: C<dynamic> |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_complex_by_cycle_typedef_functionType() async { |
| var library = await checkLibrary(''' |
| typedef C<T extends D> = void Function(); |
| typedef D<T extends C> = void Function(); |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| typeAliases |
| notSimplyBounded C @8 |
| typeParameters |
| unrelated T @10 |
| bound: dynamic |
| defaultType: dynamic |
| aliasedType: void Function() |
| aliasedElement: GenericFunctionTypeElement |
| returnType: void |
| notSimplyBounded D @50 |
| typeParameters |
| unrelated T @52 |
| bound: dynamic |
| defaultType: dynamic |
| aliasedType: void Function() |
| aliasedElement: GenericFunctionTypeElement |
| returnType: void |
| '''); |
| } |
| |
| test_class_notSimplyBounded_complex_by_cycle_typedef_interfaceType() async { |
| var library = await checkLibrary(''' |
| typedef C<T extends D> = List<T>; |
| typedef D<T extends C> = List<T>; |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| typeAliases |
| notSimplyBounded C @8 |
| typeParameters |
| covariant T @10 |
| bound: dynamic |
| defaultType: dynamic |
| aliasedType: List<T> |
| notSimplyBounded D @42 |
| typeParameters |
| covariant T @44 |
| bound: dynamic |
| defaultType: dynamic |
| aliasedType: List<T> |
| '''); |
| } |
| |
| test_class_notSimplyBounded_complex_by_reference_to_cycle() async { |
| var library = await checkLibrary(''' |
| class C<T extends D> {} |
| class D<T extends D> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: D<dynamic> |
| defaultType: D<dynamic> |
| constructors |
| synthetic @-1 |
| notSimplyBounded class D @30 |
| typeParameters |
| covariant T @32 |
| bound: D<dynamic> |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_complex_by_use_of_parameter() async { |
| var library = await checkLibrary(''' |
| class C<T extends D<T>> {} |
| class D<T> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: D<T> |
| defaultType: D<dynamic> |
| constructors |
| synthetic @-1 |
| class D @33 |
| typeParameters |
| covariant T @35 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_dependency_with_type_params() async { |
| // C's type parameter T is simply bounded because even though it refers to |
| // non-simply-bounded type D, it specifies a bound. |
| var library = await checkLibrary(''' |
| class C<T extends D<dynamic>> {} |
| class D<T extends D<T>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| bound: D<dynamic> |
| defaultType: D<dynamic> |
| constructors |
| synthetic @-1 |
| notSimplyBounded class D @39 |
| typeParameters |
| covariant T @41 |
| bound: D<T> |
| defaultType: D<dynamic> |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_function_typed_bound_complex_via_parameter_type() async { |
| var library = await checkLibrary(''' |
| class C<T extends void Function(T)> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: void Function(T) |
| defaultType: void Function(Never) |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_function_typed_bound_complex_via_parameter_type_legacy() async { |
| featureSet = FeatureSets.language_2_9; |
| var library = await checkLibrary(''' |
| class C<T extends void Function(T)> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: void Function(T*)* |
| defaultType: void Function(Null*)* |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_function_typed_bound_complex_via_return_type() async { |
| var library = await checkLibrary(''' |
| class C<T extends T Function()> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: T Function() |
| defaultType: dynamic Function() |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_function_typed_bound_simple() async { |
| var library = await checkLibrary(''' |
| class C<T extends void Function()> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| bound: void Function() |
| defaultType: void Function() |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_refers_to_circular_typedef() async { |
| // C's type parameter T has a bound of F, which is a circular typedef. This |
| // is illegal in Dart, but we need to make sure it doesn't lead to a crash |
| // or infinite loop. |
| var library = await checkLibrary(''' |
| class C<T extends F> {} |
| typedef F(G value); |
| typedef G(F value); |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: dynamic |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| typeAliases |
| functionTypeAliasBased notSimplyBounded F @32 |
| aliasedType: dynamic Function(dynamic) |
| aliasedElement: GenericFunctionTypeElement |
| parameters |
| requiredPositional value @36 |
| type: dynamic |
| returnType: dynamic |
| functionTypeAliasBased notSimplyBounded G @52 |
| aliasedType: dynamic Function(dynamic) |
| aliasedElement: GenericFunctionTypeElement |
| parameters |
| requiredPositional value @56 |
| type: dynamic |
| returnType: dynamic |
| '''); |
| } |
| |
| test_class_notSimplyBounded_self() async { |
| var library = await checkLibrary(''' |
| class C<T extends C> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: C<dynamic> |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_simple_because_non_generic() async { |
| // If no type parameters are specified, then the class is simply bounded, so |
| // there is no reason to assign it a slot. |
| var library = await checkLibrary(''' |
| class C {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_simple_by_lack_of_cycles() async { |
| var library = await checkLibrary(''' |
| class C<T extends D> {} |
| class D<T> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| bound: D<dynamic> |
| defaultType: D<dynamic> |
| constructors |
| synthetic @-1 |
| class D @30 |
| typeParameters |
| covariant T @32 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_notSimplyBounded_simple_by_syntax() async { |
| // If no bounds are specified, then the class is simply bounded by syntax |
| // alone, so there is no reason to assign it a slot. |
| var library = await checkLibrary(''' |
| class C<T> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_ref_nullability_none() async { |
| var library = await checkLibrary(''' |
| class C {} |
| C c; |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| topLevelVariables |
| static c @13 |
| type: C |
| accessors |
| synthetic static get c @-1 |
| returnType: C |
| synthetic static set c @-1 |
| parameters |
| requiredPositional _c @-1 |
| type: C |
| returnType: void |
| '''); |
| } |
| |
| test_class_ref_nullability_question() async { |
| var library = await checkLibrary(''' |
| class C {} |
| C? c; |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| topLevelVariables |
| static c @14 |
| type: C? |
| accessors |
| synthetic static get c @-1 |
| returnType: C? |
| synthetic static set c @-1 |
| parameters |
| requiredPositional _c @-1 |
| type: C? |
| returnType: void |
| '''); |
| } |
| |
| test_class_ref_nullability_star() async { |
| featureSet = FeatureSets.language_2_9; |
| var library = await checkLibrary(''' |
| class C {} |
| C c; |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| topLevelVariables |
| static c @13 |
| type: C* |
| accessors |
| synthetic static get c @-1 |
| returnType: C* |
| synthetic static set c @-1 |
| parameters |
| requiredPositional _c @-1 |
| type: C* |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_abstract() async { |
| var library = |
| await checkLibrary('abstract class C { void set x(int value); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| abstract class C @15 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| abstract set x @28 |
| parameters |
| requiredPositional value @34 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_external() async { |
| var library = |
| await checkLibrary('class C { external void set x(int value); }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| external set x @28 |
| parameters |
| requiredPositional value @34 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_implicit_param_type() async { |
| var library = await checkLibrary('class C { void set x(value) {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| set x @19 |
| parameters |
| requiredPositional value @21 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_implicit_return_type() async { |
| var library = await checkLibrary('class C { set x(int value) {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| set x @14 |
| parameters |
| requiredPositional value @20 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_invalid_named_parameter() async { |
| var library = await checkLibrary('class C { void set x({a}) {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| set x @19 |
| parameters |
| optionalNamed a @22 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_invalid_no_parameter() async { |
| var library = await checkLibrary('class C { void set x() {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| set x @19 |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_invalid_optional_parameter() async { |
| var library = await checkLibrary('class C { void set x([a]) {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| set x @19 |
| parameters |
| optionalPositional a @22 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_invalid_too_many_parameters() async { |
| var library = await checkLibrary('class C { void set x(a, b) {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| set x @19 |
| parameters |
| requiredPositional a @21 |
| type: dynamic |
| requiredPositional b @24 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_native() async { |
| var library = await checkLibrary(''' |
| class C { |
| void set x(int value) native; |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| external set x @21 |
| parameters |
| requiredPositional value @27 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_setter_static() async { |
| var library = |
| await checkLibrary('class C { static void set x(int value) {} }'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic static x @-1 |
| type: int |
| constructors |
| synthetic @-1 |
| accessors |
| static set x @26 |
| parameters |
| requiredPositional value @32 |
| type: int |
| returnType: void |
| '''); |
| } |
| |
| test_class_setters() async { |
| var library = await checkLibrary(''' |
| class C { |
| void set x(int value) {} |
| set y(value) {} |
| } |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| fields |
| synthetic x @-1 |
| type: int |
| synthetic y @-1 |
| type: dynamic |
| constructors |
| synthetic @-1 |
| accessors |
| set x @21 |
| parameters |
| requiredPositional value @27 |
| type: int |
| returnType: void |
| set y @43 |
| parameters |
| requiredPositional value @45 |
| type: dynamic |
| returnType: void |
| '''); |
| } |
| |
| test_class_supertype() async { |
| var library = await checkLibrary(''' |
| class C extends D {} |
| class D {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| supertype: D |
| constructors |
| synthetic @-1 |
| class D @27 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_supertype_typeArguments() async { |
| var library = await checkLibrary(''' |
| class C extends D<int, double> {} |
| class D<T1, T2> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| supertype: D<int, double> |
| constructors |
| synthetic @-1 |
| class D @40 |
| typeParameters |
| covariant T1 @42 |
| defaultType: dynamic |
| covariant T2 @46 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_supertype_typeArguments_self() async { |
| var library = await checkLibrary(''' |
| class A<T> {} |
| class B extends A<B> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class A @6 |
| typeParameters |
| covariant T @8 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| class B @20 |
| supertype: A<B> |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_supertype_unresolved() async { |
| var library = await checkLibrary('class C extends D {}', allowErrors: true); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_type_parameters() async { |
| var library = await checkLibrary('class C<T, U> {}'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| defaultType: dynamic |
| covariant U @11 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_type_parameters_bound() async { |
| var library = await checkLibrary(''' |
| class C<T extends Object, U extends D> {} |
| class D {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| class C @6 |
| typeParameters |
| covariant T @8 |
| bound: Object |
| defaultType: Object |
| covariant U @26 |
| bound: D |
| defaultType: D |
| constructors |
| synthetic @-1 |
| class D @48 |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_type_parameters_cycle_1of1() async { |
| var library = await checkLibrary('class C<T extends T> {}'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: dynamic |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_type_parameters_cycle_2of3() async { |
| var library = await checkLibrary(r''' |
| class C<T extends V, U, V extends T> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: dynamic |
| defaultType: dynamic |
| covariant U @21 |
| defaultType: dynamic |
| covariant V @24 |
| bound: dynamic |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_type_parameters_f_bound_complex() async { |
| var library = await checkLibrary('class C<T extends List<U>, U> {}'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: List<U> |
| defaultType: List<dynamic> |
| covariant U @27 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_type_parameters_f_bound_simple() async { |
| var library = await checkLibrary('class C<T extends U, U> {}'); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: U |
| defaultType: dynamic |
| covariant U @21 |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_cycle_genericFunctionType() async { |
| var library = await checkLibrary(r''' |
| class A<T extends void Function(A)> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @6 |
| typeParameters |
| covariant T @8 |
| bound: void Function(A<dynamic>) |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_cycle_genericFunctionType2() async { |
| var library = await checkLibrary(r''' |
| class C<T extends void Function<U extends C>()> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class C @6 |
| typeParameters |
| covariant T @8 |
| bound: void Function<U extends C<dynamic>>() |
| defaultType: dynamic |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_functionTypeAlias_contravariant_legacy() async { |
| featureSet = FeatureSets.language_2_9; |
| var library = await checkLibrary(r''' |
| typedef F<X> = void Function(X); |
| |
| class A<X extends F<X>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @40 |
| typeParameters |
| covariant X @42 |
| bound: void Function(X*)* |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| X* |
| defaultType: void Function(Null*)* |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| Null* |
| constructors |
| synthetic @-1 |
| typeAliases |
| F @8 |
| typeParameters |
| contravariant X @10 |
| defaultType: dynamic |
| aliasedType: void Function(X*)* |
| aliasedElement: GenericFunctionTypeElement |
| parameters |
| requiredPositional @-1 |
| type: X* |
| returnType: void |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_functionTypeAlias_contravariant_nullSafe() async { |
| var library = await checkLibrary(r''' |
| typedef F<X> = void Function(X); |
| |
| class A<X extends F<X>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @40 |
| typeParameters |
| covariant X @42 |
| bound: void Function(X) |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| X |
| defaultType: void Function(Never) |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| Never |
| constructors |
| synthetic @-1 |
| typeAliases |
| F @8 |
| typeParameters |
| contravariant X @10 |
| defaultType: dynamic |
| aliasedType: void Function(X) |
| aliasedElement: GenericFunctionTypeElement |
| parameters |
| requiredPositional @-1 |
| type: X |
| returnType: void |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_functionTypeAlias_covariant_nullSafe() async { |
| var library = await checkLibrary(r''' |
| typedef F<X> = X Function(); |
| |
| class A<X extends F<X>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @36 |
| typeParameters |
| covariant X @38 |
| bound: X Function() |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| X |
| defaultType: dynamic Function() |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| dynamic |
| constructors |
| synthetic @-1 |
| typeAliases |
| F @8 |
| typeParameters |
| covariant X @10 |
| defaultType: dynamic |
| aliasedType: X Function() |
| aliasedElement: GenericFunctionTypeElement |
| returnType: X |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_functionTypeAlias_invariant_legacy() async { |
| var library = await checkLibrary(r''' |
| typedef F<X> = X Function(X); |
| |
| class A<X extends F<X>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @37 |
| typeParameters |
| covariant X @39 |
| bound: X Function(X) |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| X |
| defaultType: dynamic Function(dynamic) |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| dynamic |
| constructors |
| synthetic @-1 |
| typeAliases |
| F @8 |
| typeParameters |
| invariant X @10 |
| defaultType: dynamic |
| aliasedType: X Function(X) |
| aliasedElement: GenericFunctionTypeElement |
| parameters |
| requiredPositional @-1 |
| type: X |
| returnType: X |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_functionTypeAlias_invariant_nullSafe() async { |
| var library = await checkLibrary(r''' |
| typedef F<X> = X Function(X); |
| |
| class A<X extends F<X>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @37 |
| typeParameters |
| covariant X @39 |
| bound: X Function(X) |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| X |
| defaultType: dynamic Function(dynamic) |
| aliasElement: self::@typeAlias::F |
| aliasArguments |
| dynamic |
| constructors |
| synthetic @-1 |
| typeAliases |
| F @8 |
| typeParameters |
| invariant X @10 |
| defaultType: dynamic |
| aliasedType: X Function(X) |
| aliasedElement: GenericFunctionTypeElement |
| parameters |
| requiredPositional @-1 |
| type: X |
| returnType: X |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_genericFunctionType_both_legacy() async { |
| featureSet = FeatureSets.language_2_9; |
| var library = await checkLibrary(r''' |
| class A<X extends X Function(X)> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @6 |
| typeParameters |
| covariant X @8 |
| bound: X* Function(X*)* |
| defaultType: dynamic Function(Null*)* |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_genericFunctionType_both_nullSafe() async { |
| var library = await checkLibrary(r''' |
| class A<X extends X Function(X)> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @6 |
| typeParameters |
| covariant X @8 |
| bound: X Function(X) |
| defaultType: dynamic Function(Never) |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_genericFunctionType_contravariant_legacy() async { |
| featureSet = FeatureSets.language_2_9; |
| var library = await checkLibrary(r''' |
| class A<X extends void Function(X)> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @6 |
| typeParameters |
| covariant X @8 |
| bound: void Function(X*)* |
| defaultType: void Function(Null*)* |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_genericFunctionType_contravariant_nullSafe() async { |
| var library = await checkLibrary(r''' |
| class A<X extends void Function(X)> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @6 |
| typeParameters |
| covariant X @8 |
| bound: void Function(X) |
| defaultType: void Function(Never) |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_genericFunctionType_covariant_legacy() async { |
| var library = await checkLibrary(r''' |
| class A<X extends X Function()> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @6 |
| typeParameters |
| covariant X @8 |
| bound: X Function() |
| defaultType: dynamic Function() |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_genericFunctionType_covariant_nullSafe() async { |
| var library = await checkLibrary(r''' |
| class A<X extends X Function()> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class A @6 |
| typeParameters |
| covariant X @8 |
| bound: X Function() |
| defaultType: dynamic Function() |
| constructors |
| synthetic @-1 |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_typeAlias_interface_contravariant() async { |
| var library = await checkLibrary(r''' |
| typedef A<X> = List<void Function(X)>; |
| |
| class B<X extends A<X>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class B @46 |
| typeParameters |
| covariant X @48 |
| bound: List<void Function(X)> |
| aliasElement: self::@typeAlias::A |
| aliasArguments |
| X |
| defaultType: List<void Function(Never)> |
| aliasElement: self::@typeAlias::A |
| aliasArguments |
| Never |
| constructors |
| synthetic @-1 |
| typeAliases |
| A @8 |
| typeParameters |
| contravariant X @10 |
| defaultType: dynamic |
| aliasedType: List<void Function(X)> |
| '''); |
| } |
| |
| test_class_typeParameters_defaultType_typeAlias_interface_covariant() async { |
| var library = await checkLibrary(r''' |
| typedef A<X> = Map<X, int>; |
| |
| class B<X extends A<X>> {} |
| '''); |
| checkElementText(library, r''' |
| library |
| definingUnit |
| classes |
| notSimplyBounded class B @35 |
| typeParameters |
| covariant X @37 |
| bound: Map<X, int> |
| aliasElement: self::@typeAlias::A |
| aliasArguments |
| X |
| defaultType: Map<dynamic, int> |
| aliasElement: self::@typeAlias::A |
| aliasArguments |
| dynamic |
| constructors |
| synthetic @-1 |
| typeAliases |
| A @8 |
| |