|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a
|
3 | 3 | // BSD-style license that can be found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'package:analyzer/src/error/codes.dart'; |
5 | 6 | import 'package:test_reflective_loader/test_reflective_loader.dart';
|
6 | 7 |
|
7 | 8 | import 'context_collection_resolution.dart';
|
@@ -128,6 +129,99 @@ DotShorthandInvocation
|
128 | 129 | ''');
|
129 | 130 | }
|
130 | 131 |
|
| 132 | + test_call_getter() async { |
| 133 | + await assertNoErrorsInCode(r''' |
| 134 | +class C { |
| 135 | + const C(); |
| 136 | + static C get id1 => const C(); |
| 137 | + C call() => const C(); |
| 138 | +} |
| 139 | +
|
| 140 | +void main() { |
| 141 | + C c1 = .id1(); |
| 142 | + print(c1); |
| 143 | +} |
| 144 | +'''); |
| 145 | + |
| 146 | + // The [DotShorthandInvocation] is rewritten to a |
| 147 | + // [FunctionExpressionInvocation]. |
| 148 | + var node = findNode.singleFunctionExpressionInvocation; |
| 149 | + assertResolvedNodeText(node, r''' |
| 150 | +FunctionExpressionInvocation |
| 151 | + function: DotShorthandPropertyAccess |
| 152 | + period: . |
| 153 | + propertyName: SimpleIdentifier |
| 154 | + token: id1 |
| 155 | + element: <testLibraryFragment>::@class::C::@getter::id1#element |
| 156 | + staticType: C |
| 157 | + staticType: C |
| 158 | + argumentList: ArgumentList |
| 159 | + leftParenthesis: ( |
| 160 | + rightParenthesis: ) |
| 161 | + element: <testLibraryFragment>::@class::C::@method::call#element |
| 162 | + staticInvokeType: C Function() |
| 163 | + staticType: C |
| 164 | +'''); |
| 165 | + } |
| 166 | + |
| 167 | + test_call_noCallMethod() async { |
| 168 | + await assertErrorsInCode( |
| 169 | + r''' |
| 170 | +class C { |
| 171 | + const C(); |
| 172 | + static C id1 = const C(); |
| 173 | +} |
| 174 | +
|
| 175 | +void main() { |
| 176 | + C c1 = .id1(); |
| 177 | + print(c1); |
| 178 | +} |
| 179 | +''', |
| 180 | + [ |
| 181 | + error( |
| 182 | + CompileTimeErrorCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, |
| 183 | + 77, |
| 184 | + 4, |
| 185 | + ), |
| 186 | + ], |
| 187 | + ); |
| 188 | + } |
| 189 | + |
| 190 | + test_call_property() async { |
| 191 | + await assertNoErrorsInCode(r''' |
| 192 | +class C { |
| 193 | + const C(); |
| 194 | + static C id1 = const C(); |
| 195 | + C call() => const C(); |
| 196 | +} |
| 197 | +
|
| 198 | +void main() { |
| 199 | + C c1 = .id1(); |
| 200 | + print(c1); |
| 201 | +} |
| 202 | +'''); |
| 203 | + |
| 204 | + // The [DotShorthandInvocation] is rewritten to a |
| 205 | + // [FunctionExpressionInvocation]. |
| 206 | + var node = findNode.singleFunctionExpressionInvocation; |
| 207 | + assertResolvedNodeText(node, r''' |
| 208 | +FunctionExpressionInvocation |
| 209 | + function: DotShorthandPropertyAccess |
| 210 | + period: . |
| 211 | + propertyName: SimpleIdentifier |
| 212 | + token: id1 |
| 213 | + element: <testLibraryFragment>::@class::C::@getter::id1#element |
| 214 | + staticType: C |
| 215 | + staticType: C |
| 216 | + argumentList: ArgumentList |
| 217 | + leftParenthesis: ( |
| 218 | + rightParenthesis: ) |
| 219 | + element: <testLibraryFragment>::@class::C::@method::call#element |
| 220 | + staticInvokeType: C Function() |
| 221 | + staticType: C |
| 222 | +'''); |
| 223 | + } |
| 224 | + |
131 | 225 | test_equality() async {
|
132 | 226 | await assertNoErrorsInCode('''
|
133 | 227 | class C {
|
|
0 commit comments