blob: 71a84c723a855c295445c992bd7d666dea881317 [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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const a @10
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
const b @23
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::b
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingFragment: <testLibraryFragment>
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: num
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
const b
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::b
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
synthetic static get b
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::b
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
const b @19
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::b
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingFragment: <testLibraryFragment>
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
const b
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::b
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
synthetic static get b
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::b
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
fields
f1 @29
reference: <testLibraryFragment>::@class::C::@field::f1
enclosingFragment: <testLibraryFragment>::@class::C
getter2: <testLibraryFragment>::@class::C::@getter::f1
f2 @56
reference: <testLibraryFragment>::@class::C::@field::f2
enclosingFragment: <testLibraryFragment>::@class::C
getter2: <testLibraryFragment>::@class::C::@getter::f2
f3 @67
reference: <testLibraryFragment>::@class::C::@field::f3
enclosingFragment: <testLibraryFragment>::@class::C
getter2: <testLibraryFragment>::@class::C::@getter::f3
constructors
synthetic new @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
getters
get f1 @-1
reference: <testLibraryFragment>::@class::C::@getter::f1
enclosingFragment: <testLibraryFragment>::@class::C
get f2 @-1
reference: <testLibraryFragment>::@class::C::@getter::f2
enclosingFragment: <testLibraryFragment>::@class::C
get f3 @-1
reference: <testLibraryFragment>::@class::C::@getter::f3
enclosingFragment: <testLibraryFragment>::@class::C
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::C
fields
static const f1
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
type: int
firstFragment: <testLibraryFragment>::@class::C::@field::f1
getter: <none>
static const f2
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
type: int
firstFragment: <testLibraryFragment>::@class::C::@field::f2
getter: <none>
static const f3
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
type: int
firstFragment: <testLibraryFragment>::@class::C::@field::f3
getter: <none>
constructors
synthetic new
reference: <none>
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
getters
synthetic static get f1
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
firstFragment: <testLibraryFragment>::@class::C::@getter::f1
synthetic static get f2
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
firstFragment: <testLibraryFragment>::@class::C::@getter::f2
synthetic static get f3
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
firstFragment: <testLibraryFragment>::@class::C::@getter::f3
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
typeParameters
T @8
fields
t @23
reference: <testLibraryFragment>::@class::C::@field::t
enclosingFragment: <testLibraryFragment>::@class::C
getter2: <testLibraryFragment>::@class::C::@getter::t
constructors
const new @34
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
const named @55
reference: <testLibraryFragment>::@class::C::@constructor::named
enclosingFragment: <testLibraryFragment>::@class::C
periodOffset: 54
nameEnd: 60
getters
get t @-1
reference: <testLibraryFragment>::@class::C::@getter::t
enclosingFragment: <testLibraryFragment>::@class::C
topLevelVariables
const x @85
reference: <testLibraryFragment>::@topLevelVariable::x
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::x
const y @114
reference: <testLibraryFragment>::@topLevelVariable::y
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::y
getters
get x @-1
reference: <testLibraryFragment>::@getter::x
enclosingFragment: <testLibraryFragment>
get y @-1
reference: <testLibraryFragment>::@getter::y
enclosingFragment: <testLibraryFragment>
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
typeParameters
T
firstFragment: <testLibraryFragment>::@class::C
fields
final t
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
type: T
firstFragment: <testLibraryFragment>::@class::C::@field::t
getter: <none>
constructors
const new
reference: <none>
parameters
requiredPositional final t
reference: <none>
type: T
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
const named
reference: <none>
parameters
requiredPositional final t
reference: <none>
type: T
firstFragment: <testLibraryFragment>::@class::C::@constructor::named
getters
synthetic get t
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
firstFragment: <testLibraryFragment>::@class::C::@getter::t
topLevelVariables
const x
reference: <none>
enclosingElement2: <testLibrary>
type: Object
firstFragment: <testLibraryFragment>::@topLevelVariable::x
getter: <none>
const y
reference: <none>
enclosingElement2: <testLibrary>
type: Object
firstFragment: <testLibraryFragment>::@topLevelVariable::y
getter: <none>
getters
synthetic static get x
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::x
synthetic static get y
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::y
''');
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()
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class A @6
reference: <testLibraryFragment>::@class::A
constructors
named @14
reference: <testLibraryFragment>::@class::A::@constructor::named
enclosingFragment: <testLibraryFragment>::@class::A
periodOffset: 13
nameEnd: 19
topLevelVariables
const v @31
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::v
getters
get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingFragment: <testLibraryFragment>
classes
class A
reference: <testLibraryFragment>::@class::A
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::A
constructors
named
reference: <none>
firstFragment: <testLibraryFragment>::@class::A::@constructor::named
topLevelVariables
const v
reference: <none>
enclosingElement2: <testLibrary>
type: A Function()
firstFragment: <testLibraryFragment>::@topLevelVariable::v
getter: <none>
getters
synthetic static get v
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::v
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
fields
f @22
reference: <testLibraryFragment>::@class::C::@field::f
enclosingFragment: <testLibraryFragment>::@class::C
getter2: <testLibraryFragment>::@class::C::@getter::f
constructors
const new @38
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
getters
get f @-1
reference: <testLibraryFragment>::@class::C::@getter::f
enclosingFragment: <testLibraryFragment>::@class::C
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::C
fields
final f
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
type: int
firstFragment: <testLibraryFragment>::@class::C::@field::f
getter: <none>
constructors
const new
reference: <none>
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
getters
synthetic get f
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
firstFragment: <testLibraryFragment>::@class::C::@getter::f
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const v @44
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::v
getters
get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingFragment: <testLibraryFragment>
topLevelVariables
const v
reference: <none>
enclosingElement2: <testLibrary>
type: void Function(int)
firstFragment: <testLibraryFragment>::@topLevelVariable::v
getter: <none>
getters
synthetic static get v
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::v
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const v @24
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::v
getters
get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingFragment: <testLibraryFragment>
topLevelVariables
const v
reference: <none>
enclosingElement2: <testLibrary>
type: void Function(int)
firstFragment: <testLibraryFragment>::@topLevelVariable::v
getter: <none>
getters
synthetic static get v
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::v
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
const b @21
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::b
const c @34
reference: <testLibraryFragment>::@topLevelVariable::c
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::c
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingFragment: <testLibraryFragment>
get c @-1
reference: <testLibraryFragment>::@getter::c
enclosingFragment: <testLibraryFragment>
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: List<int>
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
const b
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::b
getter: <none>
const c
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::c
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
synthetic static get b
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::b
synthetic static get c
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::c
''');
}
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>>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class P @6
reference: <testLibraryFragment>::@class::P
typeParameters
T @8
constructors
const new @21
reference: <testLibraryFragment>::@class::P::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::P
class P1 @35
reference: <testLibraryFragment>::@class::P1
typeParameters
T @38
constructors
const new @64
reference: <testLibraryFragment>::@class::P1::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::P1
superConstructor: ConstructorMember
base: <testLibraryFragment>::@class::P::@constructor::new
substitution: {T: T}
class P2 @79
reference: <testLibraryFragment>::@class::P2
typeParameters
T @82
constructors
const new @108
reference: <testLibraryFragment>::@class::P2::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::P2
superConstructor: ConstructorMember
base: <testLibraryFragment>::@class::P::@constructor::new
substitution: {T: T}
topLevelVariables
const values @131
reference: <testLibraryFragment>::@topLevelVariable::values
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::values
getters
get values @-1
reference: <testLibraryFragment>::@getter::values
enclosingFragment: <testLibraryFragment>
classes
class P
reference: <testLibraryFragment>::@class::P
enclosingElement2: <testLibrary>
typeParameters
T
firstFragment: <testLibraryFragment>::@class::P
constructors
const new
reference: <none>
firstFragment: <testLibraryFragment>::@class::P::@constructor::new
class P1
reference: <testLibraryFragment>::@class::P1
enclosingElement2: <testLibrary>
typeParameters
T
firstFragment: <testLibraryFragment>::@class::P1
supertype: P<T>
constructors
const new
reference: <none>
superConstructor: <none>
firstFragment: <testLibraryFragment>::@class::P1::@constructor::new
class P2
reference: <testLibraryFragment>::@class::P2
enclosingElement2: <testLibrary>
typeParameters
T
firstFragment: <testLibraryFragment>::@class::P2
supertype: P<T>
constructors
const new
reference: <none>
superConstructor: <none>
firstFragment: <testLibraryFragment>::@class::P2::@constructor::new
topLevelVariables
const values
reference: <none>
enclosingElement2: <testLibrary>
type: List<P<dynamic>>
firstFragment: <testLibraryFragment>::@topLevelVariable::values
getter: <none>
getters
synthetic static get values
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::values
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
fields
f @25
reference: <testLibraryFragment>::@class::C::@field::f
enclosingFragment: <testLibraryFragment>::@class::C
getter2: <testLibraryFragment>::@class::C::@getter::f
constructors
synthetic new @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
getters
get f @-1
reference: <testLibraryFragment>::@class::C::@getter::f
enclosingFragment: <testLibraryFragment>::@class::C
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::C
fields
static const f
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
type: int
firstFragment: <testLibraryFragment>::@class::C::@field::f
getter: <none>
constructors
synthetic new
reference: <none>
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
getters
synthetic static get f
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
firstFragment: <testLibraryFragment>::@class::C::@getter::f
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
fields
f @18
reference: <testLibraryFragment>::@class::C::@field::f
enclosingFragment: <testLibraryFragment>::@class::C
getter2: <testLibraryFragment>::@class::C::@getter::f
constructors
synthetic new @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
getters
get f @-1
reference: <testLibraryFragment>::@class::C::@getter::f
enclosingFragment: <testLibraryFragment>::@class::C
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::C
fields
final f
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
type: int
firstFragment: <testLibraryFragment>::@class::C::@field::f
getter: <none>
constructors
synthetic new
reference: <none>
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
getters
synthetic get f
reference: <none>
enclosingElement: <testLibraryFragment>::@class::C
firstFragment: <testLibraryFragment>::@class::C::@getter::f
''');
}
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()
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::v
getters
get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingFragment: <testLibraryFragment>
topLevelVariables
const v
reference: <none>
enclosingElement2: <testLibrary>
type: int Function()
firstFragment: <testLibraryFragment>::@topLevelVariable::v
getter: <none>
getters
synthetic static get v
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::v
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class A @6
reference: <testLibraryFragment>::@class::A
constructors
const new @19
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::A
constantInitializers
AssertInitializer
assertKeyword: assert @25
leftParenthesis: ( @31
condition: SimpleIdentifier
token: _notSerializableExpression @-1
staticElement: <null>
staticType: null
rightParenthesis: ) @46
classes
class A
reference: <testLibraryFragment>::@class::A
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::A
constructors
const new
reference: <none>
firstFragment: <testLibraryFragment>::@class::A::@constructor::new
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class A @6
reference: <testLibraryFragment>::@class::A
constructors
const new @19
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingFragment: <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
classes
class A
reference: <testLibraryFragment>::@class::A
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::A
constructors
const new
reference: <none>
firstFragment: <testLibraryFragment>::@class::A::@constructor::new
''');
}
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?
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class A @6
reference: <testLibraryFragment>::@class::A
fields
foo @26
reference: <testLibraryFragment>::@class::A::@field::foo
enclosingFragment: <testLibraryFragment>::@class::A
getter2: <testLibraryFragment>::@class::A::@getter::foo
constructors
const new @39
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingFragment: <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
getters
get foo @-1
reference: <testLibraryFragment>::@class::A::@getter::foo
enclosingFragment: <testLibraryFragment>::@class::A
classes
class A
reference: <testLibraryFragment>::@class::A
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::A
fields
final foo
reference: <none>
enclosingElement: <testLibraryFragment>::@class::A
type: Object?
firstFragment: <testLibraryFragment>::@class::A::@field::foo
getter: <none>
constructors
const new
reference: <none>
firstFragment: <testLibraryFragment>::@class::A::@constructor::new
getters
synthetic get foo
reference: <none>
enclosingElement: <testLibraryFragment>::@class::A
firstFragment: <testLibraryFragment>::@class::A::@getter::foo
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::v
getters
get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingFragment: <testLibraryFragment>
topLevelVariables
const v
reference: <none>
enclosingElement2: <testLibrary>
type: InvalidType
firstFragment: <testLibraryFragment>::@topLevelVariable::v
getter: <none>
getters
synthetic static get v
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::v
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class A @6
reference: <testLibraryFragment>::@class::A
constructors
const new @18
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::A
const named @51
reference: <testLibraryFragment>::@class::A::@constructor::named
enclosingFragment: <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
classes
class A
reference: <testLibraryFragment>::@class::A
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::A
constructors
const new
reference: <none>
parameters
requiredPositional a
reference: <none>
type: Object
requiredPositional b
reference: <none>
type: Object
firstFragment: <testLibraryFragment>::@class::A::@constructor::new
const named
reference: <none>
redirectedConstructor: <none>
firstFragment: <testLibraryFragment>::@class::A::@constructor::named
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class A @6
reference: <testLibraryFragment>::@class::A
constructors
const new @18
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::A
class B @49
reference: <testLibraryFragment>::@class::B
constructors
const new @71
reference: <testLibraryFragment>::@class::B::@constructor::new
enclosingFragment: <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
classes
class A
reference: <testLibraryFragment>::@class::A
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::A
constructors
const new
reference: <none>
parameters
requiredPositional a
reference: <none>
type: Object
requiredPositional b
reference: <none>
type: Object
firstFragment: <testLibraryFragment>::@class::A::@constructor::new
class B
reference: <testLibraryFragment>::@class::B
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::B
supertype: A
constructors
const new
reference: <none>
superConstructor: <none>
firstFragment: <testLibraryFragment>::@class::B::@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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
''');
}
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,)
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::v
getters
get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingFragment: <testLibraryFragment>
topLevelVariables
const v
reference: <none>
enclosingElement2: <testLibrary>
type: (int,)
firstFragment: <testLibraryFragment>::@topLevelVariable::v
getter: <none>
getters
synthetic static get v
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::v
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const v @6
reference: <testLibraryFragment>::@topLevelVariable::v
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::v
getters
get v @-1
reference: <testLibraryFragment>::@getter::v
enclosingFragment: <testLibraryFragment>
topLevelVariables
const v
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::v
getter: <none>
getters
synthetic static get v
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::v
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const a @6
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const a @10
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
const b @28
reference: <testLibraryFragment>::@topLevelVariable::b
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::b
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
get b @-1
reference: <testLibraryFragment>::@getter::b
enclosingFragment: <testLibraryFragment>
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: int
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
const b
reference: <none>
enclosingElement2: <testLibrary>
type: bool
firstFragment: <testLibraryFragment>::@topLevelVariable::b
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
synthetic static get b
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::b
''');
}
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>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
typeParameters
K @8
V @11
constructors
const named @26
reference: <testLibraryFragment>::@class::C::@constructor::named
enclosingFragment: <testLibraryFragment>::@class::C
periodOffset: 25
nameEnd: 31
topLevelVariables
const V @51
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
typeParameters
K
V
firstFragment: <testLibraryFragment>::@class::C
constructors
const named
reference: <none>
parameters
requiredPositional k
reference: <none>
type: K
requiredPositional v
reference: <none>
type: V
firstFragment: <testLibraryFragment>::@class::C::@constructor::named
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C<int, String>
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_generic_named_imported() async {
newFile('$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>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
libraryImports
package:test/a.dart
topLevelVariables
const V @23
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C<int, String>
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_generic_named_imported_withPrefix() async {
newFile('$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>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
libraryImports
package:test/a.dart
prefixes
p
reference: <testLibraryFragment>::@prefix::p
topLevelVariables
const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C<int, String>
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
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>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
typeParameters
K @8
V @11
constructors
const new @24
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
topLevelVariables
const V @37
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
typeParameters
K
V
firstFragment: <testLibraryFragment>::@class::C
constructors
const new
reference: <none>
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C<dynamic, dynamic>
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class A @6
reference: <testLibraryFragment>::@class::A
typeParameters
T @8
fields
t @23
reference: <testLibraryFragment>::@class::A::@field::t
enclosingFragment: <testLibraryFragment>::@class::A
getter2: <testLibraryFragment>::@class::A::@getter::t
constructors
const new @34
reference: <testLibraryFragment>::@class::A::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::A
getters
get t @-1
reference: <testLibraryFragment>::@class::A::@getter::t
enclosingFragment: <testLibraryFragment>::@class::A
topLevelVariables
const a @60
reference: <testLibraryFragment>::@topLevelVariable::a
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::a
getters
get a @-1
reference: <testLibraryFragment>::@getter::a
enclosingFragment: <testLibraryFragment>
classes
class A
reference: <testLibraryFragment>::@class::A
enclosingElement2: <testLibrary>
typeParameters
T
firstFragment: <testLibraryFragment>::@class::A
fields
final t
reference: <none>
enclosingElement: <testLibraryFragment>::@class::A
type: T
firstFragment: <testLibraryFragment>::@class::A::@field::t
getter: <none>
constructors
const new
reference: <none>
parameters
requiredPositional final t
reference: <none>
type: T
firstFragment: <testLibraryFragment>::@class::A::@constructor::new
getters
synthetic get t
reference: <none>
enclosingElement: <testLibraryFragment>::@class::A
firstFragment: <testLibraryFragment>::@class::A::@getter::t
topLevelVariables
const a
reference: <none>
enclosingElement2: <testLibrary>
type: Object
firstFragment: <testLibraryFragment>::@topLevelVariable::a
getter: <none>
getters
synthetic static get a
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::a
''');
}
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>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
typeParameters
K @8
V @11
constructors
const new @24
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
topLevelVariables
const V @37
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
typeParameters
K
V
firstFragment: <testLibraryFragment>::@class::C
constructors
const new
reference: <none>
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C<int, String>
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_generic_unnamed_imported() async {
newFile('$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>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
libraryImports
package:test/a.dart
topLevelVariables
const V @23
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C<int, String>
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_generic_unnamed_imported_withPrefix() async {
newFile('$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>
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
libraryImports
package:test/a.dart
prefixes
p
reference: <testLibraryFragment>::@prefix::p
topLevelVariables
const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C<int, String>
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
constructors
const named @20
reference: <testLibraryFragment>::@class::C::@constructor::named
enclosingFragment: <testLibraryFragment>::@class::C
periodOffset: 19
nameEnd: 25
topLevelVariables
const V @79
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::C
constructors
const named
reference: <none>
parameters
requiredPositional a
reference: <none>
type: bool
requiredPositional b
reference: <none>
type: int
requiredPositional c
reference: <none>
type: int
optionalNamed d
reference: <none>
type: String
optionalNamed e
reference: <none>
type: double
firstFragment: <testLibraryFragment>::@class::C::@constructor::named
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_named_imported() async {
newFile('$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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
libraryImports
package:test/a.dart
topLevelVariables
const V @23
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_named_imported_withPrefix() async {
newFile('$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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
libraryImports
package:test/a.dart
prefixes
p
reference: <testLibraryFragment>::@prefix::p
topLevelVariables
const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
classes
class C @6
reference: <testLibraryFragment>::@class::C
constructors
synthetic new @-1
reference: <testLibraryFragment>::@class::C::@constructor::new
enclosingFragment: <testLibraryFragment>::@class::C
topLevelVariables
const V @17
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
classes
class C
reference: <testLibraryFragment>::@class::C
enclosingElement2: <testLibrary>
firstFragment: <testLibraryFragment>::@class::C
constructors
synthetic new
reference: <none>
firstFragment: <testLibraryFragment>::@class::C::@constructor::new
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
topLevelVariables
const V @6
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: InvalidType
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_named_unresolved3() async {
newFile('$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
----------------------------------------
library
reference: <testLibrary>
fragments
<testLibraryFragment>
libraryImports
package:test/a.dart
prefixes
p
reference: <testLibraryFragment>::@prefix::p
topLevelVariables
const V @28
reference: <testLibraryFragment>::@topLevelVariable::V
enclosingFragment: <testLibraryFragment>
getter2: <testLibraryFragment>::@getter::V
getters
get V @-1
reference: <testLibraryFragment>::@getter::V
enclosingFragment: <testLibraryFragment>
topLevelVariables
const V
reference: <none>
enclosingElement2: <testLibrary>
type: C
firstFragment: <testLibraryFragment>::@topLevelVariable::V
getter: <none>
getters
synthetic static get V
reference: <none>
enclosingElement: <testLibrary>
firstFragment: <testLibraryFragment>::@getter::V
''');
}
test_const_invokeConstructor_named_unresolved4() async {
newFile('$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
----------------------------------------
library