Skip to content

Commit cb785c7

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Extension type. Fix for accessing constants from extension type, when import prefixed.
Change-Id: Ia3cdd7045276ea903f356b7e7c47a702ad4e39cf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362064 Reviewed-by: Kallen Tu <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 03964bd commit cb785c7

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Support new meta annotation: `@mustBeConst`.
1818
* Support new meta TargetKinds: `constructor`, `directive`, `enumValue`, and
1919
`typeParameter`.
20+
* Fix for accessing constants from extension type, when import prefixed.
2021

2122
## 6.4.1
2223
* Patch for crash in ffi_verifier.

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,12 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
16411641
Constant? _evaluatePropertyAccess(DartObjectImpl targetResult,
16421642
SimpleIdentifier identifier, AstNode errorNode) {
16431643
var propertyElement = identifier.staticElement;
1644+
if (propertyElement is PropertyAccessorElement &&
1645+
propertyElement.isGetter &&
1646+
propertyElement.isStatic) {
1647+
return null;
1648+
}
1649+
16441650
var propertyContainer = propertyElement?.enclosingElement;
16451651
switch (propertyContainer) {
16461652
case ExtensionElement():

pkg/analyzer/test/src/dart/constant/evaluation_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4277,6 +4277,26 @@ String a
42774277
''');
42784278
}
42794279

4280+
test_visitPropertyAccess_constant_extensionType_prefixed() async {
4281+
newFile('$testPackageLibPath/a.dart', r'''
4282+
extension type const E(int it) {
4283+
static const v = 42;
4284+
}
4285+
''');
4286+
4287+
await assertNoErrorsInCode('''
4288+
import 'a.dart' as prefix;
4289+
4290+
const x = prefix.E.v;
4291+
''');
4292+
4293+
final result = _topLevelVar('x');
4294+
assertDartObjectText(result, '''
4295+
int 42
4296+
variable: self::@variable::x
4297+
''');
4298+
}
4299+
42804300
test_visitPropertyAccess_length_extension() async {
42814301
await assertErrorsInCode('''
42824302
extension ExtObject on Object {

0 commit comments

Comments
 (0)