blob: 826c349eed6c116bcc82cef20582955859cdb938 [file] [log] [blame]
// Copyright (c) 2024, 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/ast/ast.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../../dart/resolution/node_text_expectations.dart';
import '../elements_base.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ConstElementTest_keepLinking);
defineReflectiveTests(ConstElementTest_fromBytes);
defineReflectiveTests(UpdateNodeTextExpectations);
});
}
abstract class ConstElementTest extends ElementsBaseTest {
test_const_asExpression() async {
var library = await buildLibrary('''
const num a = 0;
const b = a as int;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @10
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: num
shouldUseTypeForInitializerInference: true
constantInitializer
IntegerLiteral
literal: 0 @14
staticType: int
static const b @23
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
AsExpression
expression: SimpleIdentifier
token: a @27
staticElement: <testLibraryFragment>::@getter::a
staticType: num
asOperator: as @29
type: NamedType
name: int @32
element: dart:core::<fragment>::@class::int
type: int
staticType: int
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: num
synthetic static get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_assignmentExpression() async {
var library = await buildLibrary(r'''
const a = 0;
const b = (a += 1);
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
IntegerLiteral
literal: 0 @10
staticType: int
static const b @19
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
ParenthesizedExpression
leftParenthesis: ( @23
expression: AssignmentExpression
leftHandSide: SimpleIdentifier
token: a @24
staticElement: <null>
staticType: null
operator: += @26
rightHandSide: IntegerLiteral
literal: 1 @29
staticType: int
readElement: <testLibraryFragment>::@getter::a
readType: int
writeElement: <testLibraryFragment>::@getter::a
writeType: InvalidType
staticElement: dart:core::<fragment>::@class::num::@method::+
staticType: int
rightParenthesis: ) @30
staticType: int
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: int
synthetic static get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_cascadeExpression() async {
var library = await buildLibrary(r'''
const a = 0..isEven..abs();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
CascadeExpression
target: IntegerLiteral
literal: 0 @10
staticType: int
cascadeSections
PropertyAccess
operator: .. @11
propertyName: SimpleIdentifier
token: isEven @13
staticElement: dart:core::<fragment>::@class::int::@getter::isEven
staticType: bool
staticType: bool
MethodInvocation
operator: .. @19
methodName: SimpleIdentifier
token: abs @21
staticElement: dart:core::<fragment>::@class::int::@method::abs
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: ( @24
rightParenthesis: ) @25
staticInvokeType: int Function()
staticType: int
staticType: int
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_classField() async {
var library = await buildLibrary(r'''
class C {
static const int f1 = 1;
static const int f2 = C.f1, f3 = C.f2;
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
fields
static const f1 @29
reference: <testLibraryFragment>::@class::C::@field::f1
enclosingElement: <testLibraryFragment>::@class::C
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
IntegerLiteral
literal: 1 @34
staticType: int
static const f2 @56
reference: <testLibraryFragment>::@class::C::@field::f2
enclosingElement: <testLibraryFragment>::@class::C
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: C @61
staticElement: <testLibraryFragment>::@class::C
staticType: null
period: . @62
identifier: SimpleIdentifier
token: f1 @63
staticElement: <testLibraryFragment>::@class::C::@getter::f1
staticType: int
staticElement: <testLibraryFragment>::@class::C::@getter::f1
staticType: int
static const f3 @67
reference: <testLibraryFragment>::@class::C::@field::f3
enclosingElement: <testLibraryFragment>::@class::C
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: C @72
staticElement: <testLibraryFragment>::@class::C
staticType: null
period: . @73
identifier: SimpleIdentifier
token: f2 @74
staticElement: <testLibraryFragment>::@class::C::@getter::f2
staticType: int
staticElement: <testLibraryFragment>::@class::C::@getter::f2
staticType: int
constructors
synthetic @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
accessors
synthetic static get f1 @-1
reference: <testLibraryFragment>::@class::C::@getter::f1
enclosingElement: <testLibraryFragment>::@class::C
returnType: int
synthetic static get f2 @-1
reference: <testLibraryFragment>::@class::C::@getter::f2
enclosingElement: <testLibraryFragment>::@class::C
returnType: int
synthetic static get f3 @-1
reference: <testLibraryFragment>::@class::C::@getter::f3
enclosingElement: <testLibraryFragment>::@class::C
returnType: int
''');
}
test_const_constructor_inferred_args() async {
var library = await buildLibrary('''
class C<T> {
final T t;
const C(this.t);
const C.named(this.t);
}
const Object x = const C(0);
const Object y = const C.named(0);
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @8
defaultType: dynamic
fields
final t @23
reference: <testLibraryFragment>::@class::C::@field::t
enclosingElement: <testLibraryFragment>::@class::C
type: T
constructors
const @34
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
parameters
requiredPositional final this.t @41
type: T
field: <testLibraryFragment>::@class::C::@field::t
const named @55
reference: <testLibraryFragment>::@class::C::@constructor::named
enclosingElement: <testLibraryFragment>::@class::C
periodOffset: 54
nameEnd: 60
parameters
requiredPositional final this.t @66
type: T
field: <testLibraryFragment>::@class::C::@field::t
accessors
synthetic get t @-1
reference: <testLibraryFragment>::@class::C::@getter::t
enclosingElement: <testLibraryFragment>::@class::C
returnType: T
topLevelVariables
static const x @85
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
InstanceCreationExpression
keyword: const @89
constructorName: ConstructorName
type: NamedType
name: C @95
element: <testLibraryFragment>::@class::C
type: C<int>
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::C::@constructor::new
substitution: {T: int}
argumentList: ArgumentList
leftParenthesis: ( @96
arguments
IntegerLiteral
literal: 0 @97
staticType: int
rightParenthesis: ) @98
staticType: C<int>
static const y @114
reference: <testLibraryFragment>::@topLevelVariable::y
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
InstanceCreationExpression
keyword: const @118
constructorName: ConstructorName
type: NamedType
name: C @124
element: <testLibraryFragment>::@class::C
type: C<int>
period: . @125
name: SimpleIdentifier
token: named @126
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::C::@constructor::named
substitution: {T: dynamic}
staticType: null
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::C::@constructor::named
substitution: {T: int}
argumentList: ArgumentList
leftParenthesis: ( @131
arguments
IntegerLiteral
literal: 0 @132
staticType: int
rightParenthesis: ) @133
staticType: C<int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
synthetic static get y @-1
reference: <testLibraryFragment>::@getter::y
enclosingElement: <testLibraryFragment>
returnType: Object
''');
var x = library.definingCompilationUnit.topLevelVariables[0];
var xExpr = x.constantInitializer as InstanceCreationExpression;
var xType = xExpr.constructorName.staticElement!.returnType;
_assertTypeStr(
xType,
'C<int>',
);
var y = library.definingCompilationUnit.topLevelVariables[0];
var yExpr = y.constantInitializer as InstanceCreationExpression;
var yType = yExpr.constructorName.staticElement!.returnType;
_assertTypeStr(yType, 'C<int>');
}
test_const_constructorReference() async {
var library = await buildLibrary(r'''
class A {
A.named();
}
const v = A.named;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class A @6
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
constructors
named @14
reference: <testLibraryFragment>::@class::A::@constructor::named
enclosingElement: <testLibraryFragment>::@class::A
periodOffset: 13
nameEnd: 19
topLevelVariables
static const v @31
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: A Function()
shouldUseTypeForInitializerInference: false
constantInitializer
ConstructorReference
constructorName: ConstructorName
type: NamedType
name: A @35
element: <testLibraryFragment>::@class::A
type: null
period: . @36
name: SimpleIdentifier
token: named @37
staticElement: <testLibraryFragment>::@class::A::@constructor::named
staticType: null
staticElement: <testLibraryFragment>::@class::A::@constructor::named
staticType: A Function()
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: A Function()
''');
}
test_const_finalField_hasConstConstructor() async {
var library = await buildLibrary(r'''
class C {
final int f = 42;
const C();
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
fields
final f @22
reference: <testLibraryFragment>::@class::C::@field::f
enclosingElement: <testLibraryFragment>::@class::C
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
IntegerLiteral
literal: 42 @26
staticType: int
constructors
const @38
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
accessors
synthetic get f @-1
reference: <testLibraryFragment>::@class::C::@getter::f
enclosingElement: <testLibraryFragment>::@class::C
returnType: int
''');
}
test_const_functionExpression_typeArgumentTypes() async {
var library = await buildLibrary('''
void f<T>(T a) {}
const void Function(int) v = f;
''');
checkElementText(library, '''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const v @44
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: void Function(int)
shouldUseTypeForInitializerInference: true
constantInitializer
FunctionReference
function: SimpleIdentifier
token: f @48
staticElement: <testLibraryFragment>::@function::f
staticType: void Function<T>(T)
staticType: void Function(int)
typeArgumentTypes
int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: void Function(int)
functions
f @5
reference: <testLibraryFragment>::@function::f
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @7
defaultType: dynamic
parameters
requiredPositional a @12
type: T
returnType: void
''');
}
test_const_functionReference() async {
var library = await buildLibrary(r'''
void f<T>(T a) {}
const v = f<int>;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const v @24
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: void Function(int)
shouldUseTypeForInitializerInference: false
constantInitializer
FunctionReference
function: SimpleIdentifier
token: f @28
staticElement: <testLibraryFragment>::@function::f
staticType: void Function<T>(T)
typeArguments: TypeArgumentList
leftBracket: < @29
arguments
NamedType
name: int @30
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @33
staticType: void Function(int)
typeArgumentTypes
int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: void Function(int)
functions
f @5
reference: <testLibraryFragment>::@function::f
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @7
defaultType: dynamic
parameters
requiredPositional a @12
type: T
returnType: void
''');
}
test_const_indexExpression() async {
var library = await buildLibrary(r'''
const a = [0];
const b = 0;
const c = a[b];
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: List<int>
shouldUseTypeForInitializerInference: false
constantInitializer
ListLiteral
leftBracket: [ @10
elements
IntegerLiteral
literal: 0 @11
staticType: int
rightBracket: ] @12
staticType: List<int>
static const b @21
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
IntegerLiteral
literal: 0 @25
staticType: int
static const c @34
reference: <testLibraryFragment>::@topLevelVariable::c
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
IndexExpression
target: SimpleIdentifier
token: a @38
staticElement: <testLibraryFragment>::@getter::a
staticType: List<int>
leftBracket: [ @39
index: SimpleIdentifier
token: b @40
staticElement: <testLibraryFragment>::@getter::b
staticType: int
rightBracket: ] @41
staticElement: MethodMember
base: dart:core::<fragment>::@class::List::@method::[]
substitution: {E: int}
staticType: int
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: List<int>
synthetic static get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingElement: <testLibraryFragment>
returnType: int
synthetic static get c @-1
reference: <testLibraryFragment>::@getter::c
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_inference_downward_list() async {
var library = await buildLibrary('''
class P<T> {
const P();
}
class P1<T> extends P<T> {
const P1();
}
class P2<T> extends P<T> {
const P2();
}
const List<P> values = [
P1(),
P2<int>(),
];
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class P @6
reference: <testLibraryFragment>::@class::P
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @8
defaultType: dynamic
constructors
const @21
reference: <testLibraryFragment>::@class::P::@constructor::new
enclosingElement: <testLibraryFragment>::@class::P
class P1 @35
reference: <testLibraryFragment>::@class::P1
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @38
defaultType: dynamic
supertype: P<T>
constructors
const @64
reference: <testLibraryFragment>::@class::P1::@constructor::new
enclosingElement: <testLibraryFragment>::@class::P1
superConstructor: ConstructorMember
base: <testLibraryFragment>::@class::P::@constructor::new
substitution: {T: T}
class P2 @79
reference: <testLibraryFragment>::@class::P2
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @82
defaultType: dynamic
supertype: P<T>
constructors
const @108
reference: <testLibraryFragment>::@class::P2::@constructor::new
enclosingElement: <testLibraryFragment>::@class::P2
superConstructor: ConstructorMember
base: <testLibraryFragment>::@class::P::@constructor::new
substitution: {T: T}
topLevelVariables
static const values @131
reference: <testLibraryFragment>::@topLevelVariable::values
enclosingElement: <testLibraryFragment>
type: List<P<dynamic>>
shouldUseTypeForInitializerInference: true
constantInitializer
ListLiteral
leftBracket: [ @140
elements
InstanceCreationExpression
constructorName: ConstructorName
type: NamedType
name: P1 @144
element: <testLibraryFragment>::@class::P1
type: P1<dynamic>
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::P1::@constructor::new
substitution: {T: dynamic}
argumentList: ArgumentList
leftParenthesis: ( @146
rightParenthesis: ) @147
staticType: P1<dynamic>
InstanceCreationExpression
constructorName: ConstructorName
type: NamedType
name: P2 @152
typeArguments: TypeArgumentList
leftBracket: < @154
arguments
NamedType
name: int @155
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @158
element: <testLibraryFragment>::@class::P2
type: P2<int>
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::P2::@constructor::new
substitution: {T: int}
argumentList: ArgumentList
leftParenthesis: ( @159
rightParenthesis: ) @160
staticType: P2<int>
rightBracket: ] @163
staticType: List<P<dynamic>>
accessors
synthetic static get values @-1
reference: <testLibraryFragment>::@getter::values
enclosingElement: <testLibraryFragment>
returnType: List<P<dynamic>>
''');
}
test_const_invalid_field_const() async {
var library = await buildLibrary(r'''
class C {
static const f = 1 + foo();
}
int foo() => 42;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
fields
static const f @25
reference: <testLibraryFragment>::@class::C::@field::f
enclosingElement: <testLibraryFragment>::@class::C
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
BinaryExpression
leftOperand: IntegerLiteral
literal: 1 @29
staticType: int
operator: + @31
rightOperand: MethodInvocation
methodName: SimpleIdentifier
token: foo @33
staticElement: <testLibraryFragment>::@function::foo
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: ( @36
rightParenthesis: ) @37
staticInvokeType: int Function()
staticType: int
staticElement: dart:core::<fragment>::@class::num::@method::+
staticInvokeType: num Function(num)
staticType: int
constructors
synthetic @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
accessors
synthetic static get f @-1
reference: <testLibraryFragment>::@class::C::@getter::f
enclosingElement: <testLibraryFragment>::@class::C
returnType: int
functions
foo @46
reference: <testLibraryFragment>::@function::foo
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_invalid_field_final() async {
var library = await buildLibrary(r'''
class C {
final f = 1 + foo();
}
int foo() => 42;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
fields
final f @18
reference: <testLibraryFragment>::@class::C::@field::f
enclosingElement: <testLibraryFragment>::@class::C
type: int
shouldUseTypeForInitializerInference: false
constructors
synthetic @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
accessors
synthetic get f @-1
reference: <testLibraryFragment>::@class::C::@getter::f
enclosingElement: <testLibraryFragment>::@class::C
returnType: int
functions
foo @39
reference: <testLibraryFragment>::@function::foo
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_invalid_functionExpression() async {
var library = await buildLibrary('''
const v = () { return 0; };
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int Function()
shouldUseTypeForInitializerInference: false
constantInitializer
SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int Function()
''');
}
test_const_invalid_functionExpression_assertInitializer() async {
var library = await buildLibrary('''
class A {
const A() : assert((() => true)());
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class A @6
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
constructors
const @19
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingElement: <testLibraryFragment>::@class::A
constantInitializers
AssertInitializer
assertKeyword: assert @25
leftParenthesis: ( @31
condition: SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
rightParenthesis: ) @46
''');
}
test_const_invalid_functionExpression_assertInitializer_message() async {
var library = await buildLibrary('''
class A {
const A() : assert(b, () => 0);
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class A @6
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
constructors
const @19
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingElement: <testLibraryFragment>::@class::A
constantInitializers
AssertInitializer
assertKeyword: assert @25
leftParenthesis: ( @31
condition: SimpleIdentifier
token: b @32
staticElement: <null>
staticType: InvalidType
comma: , @33
message: SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
rightParenthesis: ) @42
''');
}
test_const_invalid_functionExpression_constructorFieldInitializer() async {
var library = await buildLibrary('''
class A {
final Object? foo;
const A() : foo = (() => 0);
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class A @6
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
fields
final foo @26
reference: <testLibraryFragment>::@class::A::@field::foo
enclosingElement: <testLibraryFragment>::@class::A
type: Object?
constructors
const @39
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingElement: <testLibraryFragment>::@class::A
constantInitializers
ConstructorFieldInitializer
fieldName: SimpleIdentifier
token: foo @45
staticElement: <testLibraryFragment>::@class::A::@field::foo
staticType: null
equals: = @49
expression: SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
accessors
synthetic get foo @-1
reference: <testLibraryFragment>::@class::A::@getter::foo
enclosingElement: <testLibraryFragment>::@class::A
returnType: Object?
''');
}
test_const_invalid_functionExpression_nested() async {
var library = await buildLibrary('''
const v = () { return 0; } + 2;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: InvalidType
shouldUseTypeForInitializerInference: false
constantInitializer
SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: InvalidType
''');
}
test_const_invalid_functionExpression_redirectingConstructorInvocation() async {
var library = await buildLibrary('''
class A {
const A(Object a, Object b);
const A.named() : this(0, () => 0);
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class A @6
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
constructors
const @18
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingElement: <testLibraryFragment>::@class::A
parameters
requiredPositional a @27
type: Object
requiredPositional b @37
type: Object
const named @51
reference: <testLibraryFragment>::@class::A::@constructor::named
enclosingElement: <testLibraryFragment>::@class::A
periodOffset: 50
nameEnd: 56
constantInitializers
RedirectingConstructorInvocation
thisKeyword: this @61
argumentList: ArgumentList
leftParenthesis: ( @65
arguments
IntegerLiteral
literal: 0 @66
staticType: int
SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
rightParenthesis: ) @76
staticElement: <testLibraryFragment>::@class::A::@constructor::new
redirectedConstructor: <testLibraryFragment>::@class::A::@constructor::new
''');
}
test_const_invalid_functionExpression_superConstructorInvocation() async {
var library = await buildLibrary('''
class A {
const A(Object a, Object b);
}
class B extends A {
const B() : super(0, () => 0);
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class A @6
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
constructors
const @18
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingElement: <testLibraryFragment>::@class::A
parameters
requiredPositional a @27
type: Object
requiredPositional b @37
type: Object
class B @49
reference: <testLibraryFragment>::@class::B
enclosingElement: <testLibraryFragment>
supertype: A
constructors
const @71
reference: <testLibraryFragment>::@class::B::@constructor::new
enclosingElement: <testLibraryFragment>::@class::B
constantInitializers
SuperConstructorInvocation
superKeyword: super @77
argumentList: ArgumentList
leftParenthesis: ( @82
arguments
IntegerLiteral
literal: 0 @83
staticType: int
SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
rightParenthesis: ) @93
staticElement: <testLibraryFragment>::@class::A::@constructor::new
superConstructor: <testLibraryFragment>::@class::A::@constructor::new
''');
}
@SkippedTest(issue: 'https://github.com/dart-lang/sdk/issues/44522')
test_const_invalid_intLiteral() async {
var library = await buildLibrary(r'''
const int x = 0x;
''');
checkElementText(library, r'''
const int x = 0;
''');
}
test_const_invalid_methodInvocation() async {
var library = await buildLibrary(r'''
const a = 'abc'.codeUnitAt(0);
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
MethodInvocation
target: SimpleStringLiteral
literal: 'abc' @10
operator: . @15
methodName: SimpleIdentifier
token: codeUnitAt @16
staticElement: dart:core::<fragment>::@class::String::@method::codeUnitAt
staticType: int Function(int)
argumentList: ArgumentList
leftParenthesis: ( @26
arguments
IntegerLiteral
literal: 0 @27
staticType: int
rightParenthesis: ) @28
staticInvokeType: int Function(int)
staticType: int
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_invalid_patternAssignment() async {
var library = await buildLibrary('''
const v = (a,) = (0,);
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: (int,)
shouldUseTypeForInitializerInference: false
constantInitializer
SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: (int,)
''');
}
test_const_invalid_topLevel() async {
var library = await buildLibrary(r'''
const v = 1 + foo();
int foo() => 42;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
BinaryExpression
leftOperand: IntegerLiteral
literal: 1 @10
staticType: int
operator: + @12
rightOperand: MethodInvocation
methodName: SimpleIdentifier
token: foo @14
staticElement: <testLibraryFragment>::@function::foo
staticType: int Function()
argumentList: ArgumentList
leftParenthesis: ( @17
rightParenthesis: ) @18
staticInvokeType: int Function()
staticType: int
staticElement: dart:core::<fragment>::@class::num::@method::+
staticInvokeType: num Function(num)
staticType: int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
functions
foo @25
reference: <testLibraryFragment>::@function::foo
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_invalid_topLevel_switchExpression() async {
var library = await buildLibrary(r'''
const a = 0 + switch (true) {_ => 1};
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_invalid_typeMismatch() async {
var library = await buildLibrary(r'''
const int a = 0;
const bool b = a + 5;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @10
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
IntegerLiteral
literal: 0 @14
staticType: int
static const b @28
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingElement: <testLibraryFragment>
type: bool
shouldUseTypeForInitializerInference: true
constantInitializer
BinaryExpression
leftOperand: SimpleIdentifier
token: a @32
staticElement: <testLibraryFragment>::@getter::a
staticType: int
operator: + @34
rightOperand: IntegerLiteral
literal: 5 @36
staticType: int
staticElement: dart:core::<fragment>::@class::num::@method::+
staticInvokeType: num Function(num)
staticType: int
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: int
synthetic static get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingElement: <testLibraryFragment>
returnType: bool
''');
}
test_const_invokeConstructor_generic_named() async {
var library = await buildLibrary(r'''
class C<K, V> {
const C.named(K k, V v);
}
const V = const C<int, String>.named(1, '222');
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
typeParameters
covariant K @8
defaultType: dynamic
covariant V @11
defaultType: dynamic
constructors
const named @26
reference: <testLibraryFragment>::@class::C::@constructor::named
enclosingElement: <testLibraryFragment>::@class::C
periodOffset: 25
nameEnd: 31
parameters
requiredPositional k @34
type: K
requiredPositional v @39
type: V
topLevelVariables
static const V @51
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<int, String>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @55
constructorName: ConstructorName
type: NamedType
name: C @61
typeArguments: TypeArgumentList
leftBracket: < @62
arguments
NamedType
name: int @63
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: String @68
element: dart:core::<fragment>::@class::String
type: String
rightBracket: > @74
element: <testLibraryFragment>::@class::C
type: C<int, String>
period: . @75
name: SimpleIdentifier
token: named @76
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::C::@constructor::named
substitution: {K: int, V: String}
staticType: null
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::C::@constructor::named
substitution: {K: int, V: String}
argumentList: ArgumentList
leftParenthesis: ( @81
arguments
IntegerLiteral
literal: 1 @82
staticType: int
SimpleStringLiteral
literal: '222' @85
rightParenthesis: ) @90
staticType: C<int, String>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<int, String>
''');
}
test_const_invokeConstructor_generic_named_imported() async {
addSource('$testPackageLibPath/a.dart', r'''
class C<K, V> {
const C.named(K k, V v);
}
''');
var library = await buildLibrary(r'''
import 'a.dart';
const V = const C<int, String>.named(1, '222');
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @23
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<int, String>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @27
constructorName: ConstructorName
type: NamedType
name: C @33
typeArguments: TypeArgumentList
leftBracket: < @34
arguments
NamedType
name: int @35
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: String @40
element: dart:core::<fragment>::@class::String
type: String
rightBracket: > @46
element: package:test/a.dart::<fragment>::@class::C
type: C<int, String>
period: . @47
name: SimpleIdentifier
token: named @48
staticElement: ConstructorMember
base: package:test/a.dart::<fragment>::@class::C::@constructor::named
substitution: {K: int, V: String}
staticType: null
staticElement: ConstructorMember
base: package:test/a.dart::<fragment>::@class::C::@constructor::named
substitution: {K: int, V: String}
argumentList: ArgumentList
leftParenthesis: ( @53
arguments
IntegerLiteral
literal: 1 @54
staticType: int
SimpleStringLiteral
literal: '222' @57
rightParenthesis: ) @62
staticType: C<int, String>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<int, String>
''');
}
test_const_invokeConstructor_generic_named_imported_withPrefix() async {
addSource('$testPackageLibPath/a.dart', r'''
class C<K, V> {
const C.named(K k, V v);
}
''');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const V = const p.C<int, String>.named(1, '222');
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<int, String>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @32
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @38
period: . @39
element: <testLibraryFragment>::@prefix::p
name: C @40
typeArguments: TypeArgumentList
leftBracket: < @41
arguments
NamedType
name: int @42
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: String @47
element: dart:core::<fragment>::@class::String
type: String
rightBracket: > @53
element: package:test/a.dart::<fragment>::@class::C
type: C<int, String>
period: . @54
name: SimpleIdentifier
token: named @55
staticElement: ConstructorMember
base: package:test/a.dart::<fragment>::@class::C::@constructor::named
substitution: {K: int, V: String}
staticType: null
staticElement: ConstructorMember
base: package:test/a.dart::<fragment>::@class::C::@constructor::named
substitution: {K: int, V: String}
argumentList: ArgumentList
leftParenthesis: ( @60
arguments
IntegerLiteral
literal: 1 @61
staticType: int
SimpleStringLiteral
literal: '222' @64
rightParenthesis: ) @69
staticType: C<int, String>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<int, String>
''');
}
test_const_invokeConstructor_generic_noTypeArguments() async {
var library = await buildLibrary(r'''
class C<K, V> {
const C();
}
const V = const C();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
typeParameters
covariant K @8
defaultType: dynamic
covariant V @11
defaultType: dynamic
constructors
const @24
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
topLevelVariables
static const V @37
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<dynamic, dynamic>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @41
constructorName: ConstructorName
type: NamedType
name: C @47
element: <testLibraryFragment>::@class::C
type: C<dynamic, dynamic>
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::C::@constructor::new
substitution: {K: dynamic, V: dynamic}
argumentList: ArgumentList
leftParenthesis: ( @48
rightParenthesis: ) @49
staticType: C<dynamic, dynamic>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<dynamic, dynamic>
''');
}
test_const_invokeConstructor_generic_noTypeArguments_inferred() async {
var library = await buildLibrary(r'''
class A<T> {
final T t;
const A(this.t);
}
const Object a = const A(0);
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class A @6
reference: <testLibraryFragment>::@class::A
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @8
defaultType: dynamic
fields
final t @23
reference: <testLibraryFragment>::@class::A::@field::t
enclosingElement: <testLibraryFragment>::@class::A
type: T
constructors
const @34
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingElement: <testLibraryFragment>::@class::A
parameters
requiredPositional final this.t @41
type: T
field: <testLibraryFragment>::@class::A::@field::t
accessors
synthetic get t @-1
reference: <testLibraryFragment>::@class::A::@getter::t
enclosingElement: <testLibraryFragment>::@class::A
returnType: T
topLevelVariables
static const a @60
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
InstanceCreationExpression
keyword: const @64
constructorName: ConstructorName
type: NamedType
name: A @70
element: <testLibraryFragment>::@class::A
type: A<int>
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::A::@constructor::new
substitution: {T: int}
argumentList: ArgumentList
leftParenthesis: ( @71
arguments
IntegerLiteral
literal: 0 @72
staticType: int
rightParenthesis: ) @73
staticType: A<int>
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_invokeConstructor_generic_unnamed() async {
var library = await buildLibrary(r'''
class C<K, V> {
const C();
}
const V = const C<int, String>();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
typeParameters
covariant K @8
defaultType: dynamic
covariant V @11
defaultType: dynamic
constructors
const @24
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
topLevelVariables
static const V @37
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<int, String>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @41
constructorName: ConstructorName
type: NamedType
name: C @47
typeArguments: TypeArgumentList
leftBracket: < @48
arguments
NamedType
name: int @49
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: String @54
element: dart:core::<fragment>::@class::String
type: String
rightBracket: > @60
element: <testLibraryFragment>::@class::C
type: C<int, String>
staticElement: ConstructorMember
base: <testLibraryFragment>::@class::C::@constructor::new
substitution: {K: int, V: String}
argumentList: ArgumentList
leftParenthesis: ( @61
rightParenthesis: ) @62
staticType: C<int, String>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<int, String>
''');
}
test_const_invokeConstructor_generic_unnamed_imported() async {
addSource('$testPackageLibPath/a.dart', r'''
class C<K, V> {
const C();
}
''');
var library = await buildLibrary(r'''
import 'a.dart';
const V = const C<int, String>();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @23
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<int, String>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @27
constructorName: ConstructorName
type: NamedType
name: C @33
typeArguments: TypeArgumentList
leftBracket: < @34
arguments
NamedType
name: int @35
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: String @40
element: dart:core::<fragment>::@class::String
type: String
rightBracket: > @46
element: package:test/a.dart::<fragment>::@class::C
type: C<int, String>
staticElement: ConstructorMember
base: package:test/a.dart::<fragment>::@class::C::@constructor::new
substitution: {K: int, V: String}
argumentList: ArgumentList
leftParenthesis: ( @47
rightParenthesis: ) @48
staticType: C<int, String>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<int, String>
''');
}
test_const_invokeConstructor_generic_unnamed_imported_withPrefix() async {
addSource('$testPackageLibPath/a.dart', r'''
class C<K, V> {
const C();
}
''');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const V = const p.C<int, String>();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<int, String>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @32
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @38
period: . @39
element: <testLibraryFragment>::@prefix::p
name: C @40
typeArguments: TypeArgumentList
leftBracket: < @41
arguments
NamedType
name: int @42
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: String @47
element: dart:core::<fragment>::@class::String
type: String
rightBracket: > @53
element: package:test/a.dart::<fragment>::@class::C
type: C<int, String>
staticElement: ConstructorMember
base: package:test/a.dart::<fragment>::@class::C::@constructor::new
substitution: {K: int, V: String}
argumentList: ArgumentList
leftParenthesis: ( @54
rightParenthesis: ) @55
staticType: C<int, String>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<int, String>
''');
}
test_const_invokeConstructor_named() async {
var library = await buildLibrary(r'''
class C {
const C.named(bool a, int b, int c, {String d, double e});
}
const V = const C.named(true, 1, 2, d: 'ccc', e: 3.4);
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
constructors
const named @20
reference: <testLibraryFragment>::@class::C::@constructor::named
enclosingElement: <testLibraryFragment>::@class::C
periodOffset: 19
nameEnd: 25
parameters
requiredPositional a @31
type: bool
requiredPositional b @38
type: int
requiredPositional c @45
type: int
optionalNamed default d @56
reference: <testLibraryFragment>::@class::C::@constructor::named::@parameter::d
type: String
optionalNamed default e @66
reference: <testLibraryFragment>::@class::C::@constructor::named::@parameter::e
type: double
topLevelVariables
static const V @79
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @83
constructorName: ConstructorName
type: NamedType
name: C @89
element: <testLibraryFragment>::@class::C
type: C
period: . @90
name: SimpleIdentifier
token: named @91
staticElement: <testLibraryFragment>::@class::C::@constructor::named
staticType: null
staticElement: <testLibraryFragment>::@class::C::@constructor::named
argumentList: ArgumentList
leftParenthesis: ( @96
arguments
BooleanLiteral
literal: true @97
staticType: bool
IntegerLiteral
literal: 1 @103
staticType: int
IntegerLiteral
literal: 2 @106
staticType: int
NamedExpression
name: Label
label: SimpleIdentifier
token: d @109
staticElement: <testLibraryFragment>::@class::C::@constructor::named::@parameter::d
staticType: null
colon: : @110
expression: SimpleStringLiteral
literal: 'ccc' @112
NamedExpression
name: Label
label: SimpleIdentifier
token: e @119
staticElement: <testLibraryFragment>::@class::C::@constructor::named::@parameter::e
staticType: null
colon: : @120
expression: DoubleLiteral
literal: 3.4 @122
staticType: double
rightParenthesis: ) @125
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_named_imported() async {
addSource('$testPackageLibPath/a.dart', r'''
class C {
const C.named();
}
''');
var library = await buildLibrary(r'''
import 'a.dart';
const V = const C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @23
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @27
constructorName: ConstructorName
type: NamedType
name: C @33
element: package:test/a.dart::<fragment>::@class::C
type: C
period: . @34
name: SimpleIdentifier
token: named @35
staticElement: package:test/a.dart::<fragment>::@class::C::@constructor::named
staticType: null
staticElement: package:test/a.dart::<fragment>::@class::C::@constructor::named
argumentList: ArgumentList
leftParenthesis: ( @40
rightParenthesis: ) @41
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_named_imported_withPrefix() async {
addSource('$testPackageLibPath/a.dart', r'''
class C {
const C.named();
}
''');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const V = const p.C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @32
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @38
period: . @39
element: <testLibraryFragment>::@prefix::p
name: C @40
element: package:test/a.dart::<fragment>::@class::C
type: C
period: . @41
name: SimpleIdentifier
token: named @42
staticElement: package:test/a.dart::<fragment>::@class::C::@constructor::named
staticType: null
staticElement: package:test/a.dart::<fragment>::@class::C::@constructor::named
argumentList: ArgumentList
leftParenthesis: ( @47
rightParenthesis: ) @48
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_named_unresolved() async {
var library = await buildLibrary(r'''
class C {}
const V = const C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
constructors
synthetic @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
topLevelVariables
static const V @17
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @21
constructorName: ConstructorName
type: NamedType
name: C @27
element: <testLibraryFragment>::@class::C
type: C
period: . @28
name: SimpleIdentifier
token: named @29
staticElement: <null>
staticType: null
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @34
rightParenthesis: ) @35
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_named_unresolved2() async {
var library = await buildLibrary(r'''
const V = const C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const V @6
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: InvalidType
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @10
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: C @16
period: . @17
element: <null>
name: named @18
element: <null>
type: InvalidType
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @23
rightParenthesis: ) @24
staticType: InvalidType
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: InvalidType
''');
}
test_const_invokeConstructor_named_unresolved3() async {
addSource('$testPackageLibPath/a.dart', r'''
class C {
}
''');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const V = const p.C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @32
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @38
period: . @39
element: <testLibraryFragment>::@prefix::p
name: C @40
element: package:test/a.dart::<fragment>::@class::C
type: C
period: . @41
name: SimpleIdentifier
token: named @42
staticElement: <null>
staticType: null
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @47
rightParenthesis: ) @48
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_named_unresolved4() async {
addSource('$testPackageLibPath/a.dart', '');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const V = const p.C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: InvalidType
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @32
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @38
period: . @39
element: <testLibraryFragment>::@prefix::p
name: C @40
element: <null>
type: InvalidType
period: . @41
name: SimpleIdentifier
token: named @42
staticElement: <null>
staticType: null
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @47
rightParenthesis: ) @48
staticType: InvalidType
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: InvalidType
''');
}
test_const_invokeConstructor_named_unresolved5() async {
var library = await buildLibrary(r'''
const V = const p.C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const V @6
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: InvalidType
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @10
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @16
period: . @17
element: <null>
name: C @18
element: <null>
type: InvalidType
period: . @19
name: SimpleIdentifier
token: named @20
staticElement: <null>
staticType: null
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @25
rightParenthesis: ) @26
staticType: InvalidType
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: InvalidType
''');
}
test_const_invokeConstructor_named_unresolved6() async {
var library = await buildLibrary(r'''
class C<T> {}
const V = const C.named();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @8
defaultType: dynamic
constructors
synthetic @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
topLevelVariables
static const V @20
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C<dynamic>
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @24
constructorName: ConstructorName
type: NamedType
name: C @30
element: <testLibraryFragment>::@class::C
type: C<dynamic>
period: . @31
name: SimpleIdentifier
token: named @32
staticElement: <null>
staticType: null
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @37
rightParenthesis: ) @38
staticType: C<dynamic>
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C<dynamic>
''');
}
test_const_invokeConstructor_unnamed() async {
var library = await buildLibrary(r'''
class C {
const C();
}
const V = const C();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
constructors
const @18
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
topLevelVariables
static const V @31
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @35
constructorName: ConstructorName
type: NamedType
name: C @41
element: <testLibraryFragment>::@class::C
type: C
staticElement: <testLibraryFragment>::@class::C::@constructor::new
argumentList: ArgumentList
leftParenthesis: ( @42
rightParenthesis: ) @43
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_unnamed_imported() async {
addSource('$testPackageLibPath/a.dart', r'''
class C {
const C();
}
''');
var library = await buildLibrary(r'''
import 'a.dart';
const V = const C();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @23
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @27
constructorName: ConstructorName
type: NamedType
name: C @33
element: package:test/a.dart::<fragment>::@class::C
type: C
staticElement: package:test/a.dart::<fragment>::@class::C::@constructor::new
argumentList: ArgumentList
leftParenthesis: ( @34
rightParenthesis: ) @35
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_unnamed_imported_withPrefix() async {
addSource('$testPackageLibPath/a.dart', r'''
class C {
const C();
}
''');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const V = const p.C();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: C
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @32
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @38
period: . @39
element: <testLibraryFragment>::@prefix::p
name: C @40
element: package:test/a.dart::<fragment>::@class::C
type: C
staticElement: package:test/a.dart::<fragment>::@class::C::@constructor::new
argumentList: ArgumentList
leftParenthesis: ( @41
rightParenthesis: ) @42
staticType: C
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: C
''');
}
test_const_invokeConstructor_unnamed_unresolved() async {
var library = await buildLibrary(r'''
const V = const C();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const V @6
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: InvalidType
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @10
constructorName: ConstructorName
type: NamedType
name: C @16
element: <null>
type: InvalidType
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @17
rightParenthesis: ) @18
staticType: InvalidType
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: InvalidType
''');
}
test_const_invokeConstructor_unnamed_unresolved2() async {
addSource('$testPackageLibPath/a.dart', '');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const V = const p.C();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: InvalidType
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @32
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @38
period: . @39
element: <testLibraryFragment>::@prefix::p
name: C @40
element: <null>
type: InvalidType
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @41
rightParenthesis: ) @42
staticType: InvalidType
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: InvalidType
''');
}
test_const_invokeConstructor_unnamed_unresolved3() async {
var library = await buildLibrary(r'''
const V = const p.C();
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const V @6
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingElement: <testLibraryFragment>
type: InvalidType
shouldUseTypeForInitializerInference: false
constantInitializer
InstanceCreationExpression
keyword: const @10
constructorName: ConstructorName
type: NamedType
importPrefix: ImportPrefixReference
name: p @16
period: . @17
element: <null>
name: C @18
element: <null>
type: InvalidType
staticElement: <null>
argumentList: ArgumentList
leftParenthesis: ( @19
rightParenthesis: ) @20
staticType: InvalidType
accessors
synthetic static get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingElement: <testLibraryFragment>
returnType: InvalidType
''');
}
test_const_isExpression() async {
var library = await buildLibrary('''
const a = 0;
const b = a is int;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
IntegerLiteral
literal: 0 @10
staticType: int
static const b @19
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingElement: <testLibraryFragment>
type: bool
shouldUseTypeForInitializerInference: false
constantInitializer
IsExpression
expression: SimpleIdentifier
token: a @23
staticElement: <testLibraryFragment>::@getter::a
staticType: int
isOperator: is @25
type: NamedType
name: int @28
element: dart:core::<fragment>::@class::int
type: int
staticType: bool
accessors
synthetic static get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingElement: <testLibraryFragment>
returnType: int
synthetic static get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingElement: <testLibraryFragment>
returnType: bool
''');
}
test_const_length_ofClassConstField() async {
var library = await buildLibrary(r'''
class C {
static const String F = '';
}
const int v = C.F.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
fields
static const F @32
reference: <testLibraryFragment>::@class::C::@field::F
enclosingElement: <testLibraryFragment>::@class::C
type: String
shouldUseTypeForInitializerInference: true
constantInitializer
SimpleStringLiteral
literal: '' @36
constructors
synthetic @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
accessors
synthetic static get F @-1
reference: <testLibraryFragment>::@class::C::@getter::F
enclosingElement: <testLibraryFragment>::@class::C
returnType: String
topLevelVariables
static const v @52
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
PropertyAccess
target: PrefixedIdentifier
prefix: SimpleIdentifier
token: C @56
staticElement: <testLibraryFragment>::@class::C
staticType: null
period: . @57
identifier: SimpleIdentifier
token: F @58
staticElement: <testLibraryFragment>::@class::C::@getter::F
staticType: String
staticElement: <testLibraryFragment>::@class::C::@getter::F
staticType: String
operator: . @59
propertyName: SimpleIdentifier
token: length @60
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
staticType: int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_length_ofClassConstField_imported() async {
addSource('$testPackageLibPath/a.dart', r'''
class C {
static const String F = '';
}
''');
var library = await buildLibrary(r'''
import 'a.dart';
const int v = C.F.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const v @27
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
PropertyAccess
target: PrefixedIdentifier
prefix: SimpleIdentifier
token: C @31
staticElement: package:test/a.dart::<fragment>::@class::C
staticType: null
period: . @32
identifier: SimpleIdentifier
token: F @33
staticElement: package:test/a.dart::<fragment>::@class::C::@getter::F
staticType: String
staticElement: package:test/a.dart::<fragment>::@class::C::@getter::F
staticType: String
operator: . @34
propertyName: SimpleIdentifier
token: length @35
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
staticType: int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_length_ofClassConstField_imported_withPrefix() async {
addSource('$testPackageLibPath/a.dart', r'''
class C {
static const String F = '';
}
''');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const int v = p.C.F.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const v @32
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: true
constantInitializer
PropertyAccess
target: PropertyAccess
target: PrefixedIdentifier
prefix: SimpleIdentifier
token: p @36
staticElement: <testLibraryFragment>::@prefix::p
staticType: null
period: . @37
identifier: SimpleIdentifier
token: C @38
staticElement: package:test/a.dart::<fragment>::@class::C
staticType: null
staticElement: package:test/a.dart::<fragment>::@class::C
staticType: null
operator: . @39
propertyName: SimpleIdentifier
token: F @40
staticElement: package:test/a.dart::<fragment>::@class::C::@getter::F
staticType: String
staticType: String
operator: . @41
propertyName: SimpleIdentifier
token: length @42
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
staticType: int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_length_ofStringLiteral() async {
var library = await buildLibrary(r'''
const v = 'abc'.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
PropertyAccess
target: SimpleStringLiteral
literal: 'abc' @10
operator: . @15
propertyName: SimpleIdentifier
token: length @16
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
staticType: int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_length_ofTopLevelVariable() async {
var library = await buildLibrary(r'''
const String S = 'abc';
const v = S.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const S @13
reference: <testLibraryFragment>::@topLevelVariable::S
enclosingElement: <testLibraryFragment>
type: String
shouldUseTypeForInitializerInference: true
constantInitializer
SimpleStringLiteral
literal: 'abc' @17
static const v @30
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: S @34
staticElement: <testLibraryFragment>::@getter::S
staticType: String
period: . @35
identifier: SimpleIdentifier
token: length @36
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
accessors
synthetic static get S @-1
reference: <testLibraryFragment>::@getter::S
enclosingElement: <testLibraryFragment>
returnType: String
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_length_ofTopLevelVariable_imported() async {
addSource('$testPackageLibPath/a.dart', r'''
const String S = 'abc';
''');
var library = await buildLibrary(r'''
import 'a.dart';
const v = S.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const v @23
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: S @27
staticElement: package:test/a.dart::<fragment>::@getter::S
staticType: String
period: . @28
identifier: SimpleIdentifier
token: length @29
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_length_ofTopLevelVariable_imported_withPrefix() async {
addSource('$testPackageLibPath/a.dart', r'''
const String S = 'abc';
''');
var library = await buildLibrary(r'''
import 'a.dart' as p;
const v = p.S.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
prefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
libraryImports
package:test/a.dart as p @19
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
libraryImportPrefixes
p @19
reference: <testLibraryFragment>::@prefix::p
enclosingElement: <testLibrary>
enclosingElement3: <testLibraryFragment>
topLevelVariables
static const v @28
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
PropertyAccess
target: PrefixedIdentifier
prefix: SimpleIdentifier
token: p @32
staticElement: <testLibraryFragment>::@prefix::p
staticType: null
period: . @33
identifier: SimpleIdentifier
token: S @34
staticElement: package:test/a.dart::<fragment>::@getter::S
staticType: String
staticElement: package:test/a.dart::<fragment>::@getter::S
staticType: String
operator: . @35
propertyName: SimpleIdentifier
token: length @36
staticElement: dart:core::<fragment>::@class::String::@getter::length
staticType: int
staticType: int
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_length_staticMethod() async {
var library = await buildLibrary(r'''
class C {
static int length() => 42;
}
const v = C.length;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
constructors
synthetic @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
methods
static length @23
reference: <testLibraryFragment>::@class::C::@method::length
enclosingElement: <testLibraryFragment>::@class::C
returnType: int
topLevelVariables
static const v @47
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingElement: <testLibraryFragment>
type: int Function()
shouldUseTypeForInitializerInference: false
constantInitializer
PrefixedIdentifier
prefix: SimpleIdentifier
token: C @51
staticElement: <testLibraryFragment>::@class::C
staticType: null
period: . @52
identifier: SimpleIdentifier
token: length @53
staticElement: <testLibraryFragment>::@class::C::@method::length
staticType: int Function()
staticElement: <testLibraryFragment>::@class::C::@method::length
staticType: int Function()
accessors
synthetic static get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingElement: <testLibraryFragment>
returnType: int Function()
''');
}
test_const_list_if() async {
var library = await buildLibrary('''
const Object x = const <int>[if (true) 1];
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
ListLiteral
constKeyword: const @17
typeArguments: TypeArgumentList
leftBracket: < @23
arguments
NamedType
name: int @24
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @27
leftBracket: [ @28
elements
IfElement
ifKeyword: if @29
leftParenthesis: ( @32
expression: BooleanLiteral
literal: true @33
staticType: bool
rightParenthesis: ) @37
thenElement: IntegerLiteral
literal: 1 @39
staticType: int
rightBracket: ] @40
staticType: List<int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_list_if_else() async {
var library = await buildLibrary('''
const Object x = const <int>[if (true) 1 else 2];
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
ListLiteral
constKeyword: const @17
typeArguments: TypeArgumentList
leftBracket: < @23
arguments
NamedType
name: int @24
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @27
leftBracket: [ @28
elements
IfElement
ifKeyword: if @29
leftParenthesis: ( @32
expression: BooleanLiteral
literal: true @33
staticType: bool
rightParenthesis: ) @37
thenElement: IntegerLiteral
literal: 1 @39
staticType: int
elseKeyword: else @41
elseElement: IntegerLiteral
literal: 2 @46
staticType: int
rightBracket: ] @47
staticType: List<int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_list_inferredType() async {
// The summary needs to contain enough information so that when the constant
// is resynthesized, the constant value can get the type that was computed
// by type inference.
var library = await buildLibrary('''
const Object x = const [1];
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
ListLiteral
constKeyword: const @17
leftBracket: [ @23
elements
IntegerLiteral
literal: 1 @24
staticType: int
rightBracket: ] @25
staticType: List<int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_list_spread() async {
var library = await buildLibrary('''
const Object x = const <int>[...<int>[1]];
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
ListLiteral
constKeyword: const @17
typeArguments: TypeArgumentList
leftBracket: < @23
arguments
NamedType
name: int @24
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @27
leftBracket: [ @28
elements
SpreadElement
spreadOperator: ... @29
expression: ListLiteral
typeArguments: TypeArgumentList
leftBracket: < @32
arguments
NamedType
name: int @33
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @36
leftBracket: [ @37
elements
IntegerLiteral
literal: 1 @38
staticType: int
rightBracket: ] @39
staticType: List<int>
rightBracket: ] @40
staticType: List<int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_list_spread_null_aware() async {
var library = await buildLibrary('''
const Object x = const <int>[...?<int>[1]];
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
ListLiteral
constKeyword: const @17
typeArguments: TypeArgumentList
leftBracket: < @23
arguments
NamedType
name: int @24
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @27
leftBracket: [ @28
elements
SpreadElement
spreadOperator: ...? @29
expression: ListLiteral
typeArguments: TypeArgumentList
leftBracket: < @33
arguments
NamedType
name: int @34
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @37
leftBracket: [ @38
elements
IntegerLiteral
literal: 1 @39
staticType: int
rightBracket: ] @40
staticType: List<int>
rightBracket: ] @41
staticType: List<int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_map_if() async {
var library = await buildLibrary('''
const Object x = const <int, int>{if (true) 1: 2};
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
SetOrMapLiteral
constKeyword: const @17
typeArguments: TypeArgumentList
leftBracket: < @23
arguments
NamedType
name: int @24
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: int @29
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @32
leftBracket: { @33
elements
IfElement
ifKeyword: if @34
leftParenthesis: ( @37
expression: BooleanLiteral
literal: true @38
staticType: bool
rightParenthesis: ) @42
thenElement: MapLiteralEntry
key: IntegerLiteral
literal: 1 @44
staticType: int
separator: : @45
value: IntegerLiteral
literal: 2 @47
staticType: int
rightBracket: } @48
isMap: true
staticType: Map<int, int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_map_inferredType() async {
// The summary needs to contain enough information so that when the constant
// is resynthesized, the constant value can get the type that was computed
// by type inference.
var library = await buildLibrary('''
const Object x = const {1: 1.0};
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
SetOrMapLiteral
constKeyword: const @17
leftBracket: { @23
elements
MapLiteralEntry
key: IntegerLiteral
literal: 1 @24
staticType: int
separator: : @25
value: DoubleLiteral
literal: 1.0 @27
staticType: double
rightBracket: } @30
isMap: true
staticType: Map<int, double>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_map_spread() async {
var library = await buildLibrary('''
const Object x = const <int, int>{...<int, int>{1: 2}};
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
SetOrMapLiteral
constKeyword: const @17
typeArguments: TypeArgumentList
leftBracket: < @23
arguments
NamedType
name: int @24
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: int @29
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @32
leftBracket: { @33
elements
SpreadElement
spreadOperator: ... @34
expression: SetOrMapLiteral
typeArguments: TypeArgumentList
leftBracket: < @37
arguments
NamedType
name: int @38
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: int @43
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @46
leftBracket: { @47
elements
MapLiteralEntry
key: IntegerLiteral
literal: 1 @48
staticType: int
separator: : @49
value: IntegerLiteral
literal: 2 @51
staticType: int
rightBracket: } @52
isMap: true
staticType: Map<int, int>
rightBracket: } @53
isMap: true
staticType: Map<int, int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_map_spread_null_aware() async {
var library = await buildLibrary('''
const Object x = const <int, int>{...?<int, int>{1: 2}};
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const x @13
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingElement: <testLibraryFragment>
type: Object
shouldUseTypeForInitializerInference: true
constantInitializer
SetOrMapLiteral
constKeyword: const @17
typeArguments: TypeArgumentList
leftBracket: < @23
arguments
NamedType
name: int @24
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: int @29
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @32
leftBracket: { @33
elements
SpreadElement
spreadOperator: ...? @34
expression: SetOrMapLiteral
typeArguments: TypeArgumentList
leftBracket: < @38
arguments
NamedType
name: int @39
element: dart:core::<fragment>::@class::int
type: int
NamedType
name: int @44
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @47
leftBracket: { @48
elements
MapLiteralEntry
key: IntegerLiteral
literal: 1 @49
staticType: int
separator: : @50
value: IntegerLiteral
literal: 2 @52
staticType: int
rightBracket: } @53
isMap: true
staticType: Map<int, int>
rightBracket: } @54
isMap: true
staticType: Map<int, int>
accessors
synthetic static get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingElement: <testLibraryFragment>
returnType: Object
''');
}
test_const_methodInvocation() async {
var library = await buildLibrary(r'''
T f<T>(T a) => a;
const b = f<int>(0);
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
topLevelVariables
static const b @24
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingElement: <testLibraryFragment>
type: int
shouldUseTypeForInitializerInference: false
constantInitializer
MethodInvocation
methodName: SimpleIdentifier
token: f @28
staticElement: <testLibraryFragment>::@function::f
staticType: T Function<T>(T)
typeArguments: TypeArgumentList
leftBracket: < @29
arguments
NamedType
name: int @30
element: dart:core::<fragment>::@class::int
type: int
rightBracket: > @33
argumentList: ArgumentList
leftParenthesis: ( @34
arguments
IntegerLiteral
literal: 0 @35
staticType: int
rightParenthesis: ) @36
staticInvokeType: int Function(int)
staticType: int
typeArgumentTypes
int
accessors
synthetic static get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingElement: <testLibraryFragment>
returnType: int
functions
f @2
reference: <testLibraryFragment>::@function::f
enclosingElement: <testLibraryFragment>
typeParameters
covariant T @4
defaultType: dynamic
parameters
requiredPositional a @9
type: T
returnType: T
''');
}
test_const_parameterDefaultValue_initializingFormal_functionTyped() async {
var library = await buildLibrary(r'''
class C {
final x;
const C({this.x: foo});
}
int foo() => 42;
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
fields
final x @18
reference: <testLibraryFragment>::@class::C::@field::x
enclosingElement: <testLibraryFragment>::@class::C
type: dynamic
constructors
const @29
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
parameters
optionalNamed default final this.x @37
reference: <testLibraryFragment>::@class::C::@constructor::new::@parameter::x
type: dynamic
constantInitializer
SimpleIdentifier
token: foo @40
staticElement: <testLibraryFragment>::@function::foo
staticType: int Function()
field: <testLibraryFragment>::@class::C::@field::x
accessors
synthetic get x @-1
reference: <testLibraryFragment>::@class::C::@getter::x
enclosingElement: <testLibraryFragment>::@class::C
returnType: dynamic
functions
foo @53
reference: <testLibraryFragment>::@function::foo
enclosingElement: <testLibraryFragment>
returnType: int
''');
}
test_const_parameterDefaultValue_initializingFormal_named() async {
var library = await buildLibrary(r'''
class C {
final x;
const C({this.x: 1 + 2});
}
''');
checkElementText(library, r'''
library
reference: <testLibrary>
definingUnit: <testLibraryFragment>
units
<testLibraryFragment>
enclosingElement: <testLibrary>
classes
class C @6
reference: <testLibraryFragment>::@class::C
enclosingElement: <testLibraryFragment>
fields
final x @18
reference: <testLibraryFragment>::@class::C::@field::x
enclosingElement: <testLibraryFragment>::@class::C
type: dynamic
constructors
const @29
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingElement: <testLibraryFragment>::@class::C
parameters
optionalNamed default final this.x @37
reference: <testLibraryFragment>::@class::C::@constructor::new::@parameter::x
type: dynamic
constantInitializer
BinaryExpression
leftOperand: IntegerLiteral
literal: 1 @40
staticType: int
operator: + @42
rightOperand: IntegerLiteral
literal: 2 @44
staticType: int
staticElement: dart:core::<fragment>::@class::num::@method::+
staticInvokeType: num Function(num)
staticType: int
field: <testLibraryFragment>::@class::C::@field::x
accessors
synthetic get x @-1
reference: <testLibraryFragment>::@class::C::@getter::x
enclosingElement: <testLibraryFragment>::@class::C
returnType: dynamic
''');
}