From cb785c7ad60458dbb223fb57a2741260fccffa52 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 9 Apr 2024 21:58:15 +0000 Subject: [PATCH 1/3] 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 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- pkg/analyzer/CHANGELOG.md | 1 + .../lib/src/dart/constant/evaluation.dart | 6 ++++++ .../src/dart/constant/evaluation_test.dart | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md index 1ef57b836378..cdf15212b3cd 100644 --- a/pkg/analyzer/CHANGELOG.md +++ b/pkg/analyzer/CHANGELOG.md @@ -17,6 +17,7 @@ * Support new meta annotation: `@mustBeConst`. * Support new meta TargetKinds: `constructor`, `directive`, `enumValue`, and `typeParameter`. +* Fix for accessing constants from extension type, when import prefixed. ## 6.4.1 * Patch for crash in ffi_verifier. diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart index 0a38e5b322e7..23474565a390 100644 --- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart +++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart @@ -1641,6 +1641,12 @@ class ConstantVisitor extends UnifyingAstVisitor { Constant? _evaluatePropertyAccess(DartObjectImpl targetResult, SimpleIdentifier identifier, AstNode errorNode) { var propertyElement = identifier.staticElement; + if (propertyElement is PropertyAccessorElement && + propertyElement.isGetter && + propertyElement.isStatic) { + return null; + } + var propertyContainer = propertyElement?.enclosingElement; switch (propertyContainer) { case ExtensionElement(): diff --git a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart index 439abbceb00f..884bcdab834c 100644 --- a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart +++ b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart @@ -4277,6 +4277,26 @@ String a '''); } + test_visitPropertyAccess_constant_extensionType_prefixed() async { + newFile('$testPackageLibPath/a.dart', r''' +extension type const E(int it) { + static const v = 42; +} +'''); + + await assertNoErrorsInCode(''' +import 'a.dart' as prefix; + +const x = prefix.E.v; +'''); + + final result = _topLevelVar('x'); + assertDartObjectText(result, ''' +int 42 + variable: self::@variable::x +'''); + } + test_visitPropertyAccess_length_extension() async { await assertErrorsInCode(''' extension ExtObject on Object { From 18c0a39f672f0df29d93f346c03811f11e9fa5a3 Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 9 Apr 2024 22:24:23 +0000 Subject: [PATCH 2/3] don't lint `prefer_void_to_null` on augmented fields/top-level vars Fixes: https://github.com/dart-lang/linter/issues/4890 Change-Id: I9a44793e2e79ae946b5f010b9e588a6b8f29fc80 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362065 Reviewed-by: Brian Wilkerson Commit-Queue: Phil Quitslund --- pkg/linter/lib/src/extensions.dart | 2 ++ pkg/linter/lib/src/rules/prefer_void_to_null.dart | 8 +++++--- pkg/linter/test/rules/prefer_void_to_null_test.dart | 7 ------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pkg/linter/lib/src/extensions.dart b/pkg/linter/lib/src/extensions.dart index 72a6a5196dc6..d6b19a7c20c9 100644 --- a/pkg/linter/lib/src/extensions.dart +++ b/pkg/linter/lib/src/extensions.dart @@ -30,10 +30,12 @@ extension AstNodeExtension on AstNode { return switch (self) { ClassDeclaration() => self.augmentKeyword != null, ConstructorDeclaration() => self.augmentKeyword != null, + FieldDeclaration() => self.augmentKeyword != null, FunctionDeclarationImpl() => self.augmentKeyword != null, FunctionExpression() => self.parent?.isAugmentation ?? false, MethodDeclaration() => self.augmentKeyword != null, MixinDeclaration() => self.augmentKeyword != null, + TopLevelVariableDeclaration() => self.augmentKeyword != null, VariableDeclaration(declaredElement: var element) => element is PropertyInducingElement && element.isAugmentation, _ => false diff --git a/pkg/linter/lib/src/rules/prefer_void_to_null.dart b/pkg/linter/lib/src/rules/prefer_void_to_null.dart index fb6e78cc7c4e..3790d9cc08f1 100644 --- a/pkg/linter/lib/src/rules/prefer_void_to_null.dart +++ b/pkg/linter/lib/src/rules/prefer_void_to_null.dart @@ -154,9 +154,11 @@ class _Visitor extends SimpleAstVisitor { } if (parent != null) { - AstNode? member = parent.thisOrAncestorOfType(); - member ??= parent.thisOrAncestorOfType(); - if (member?.isAugmentation ?? false) return; + AstNode? declaration = parent.thisOrAncestorOfType(); + declaration ??= parent.thisOrAncestorOfType(); + declaration ??= + parent.thisOrAncestorOfType(); + if (declaration?.isAugmentation ?? false) return; } rule.reportLintForToken(node.name2); diff --git a/pkg/linter/test/rules/prefer_void_to_null_test.dart b/pkg/linter/test/rules/prefer_void_to_null_test.dart index d798d0fcda02..00d8a85d0f41 100644 --- a/pkg/linter/test/rules/prefer_void_to_null_test.dart +++ b/pkg/linter/test/rules/prefer_void_to_null_test.dart @@ -17,9 +17,6 @@ class PreferVoidToNullTest extends LintRuleTest { @override String get lintRule => 'prefer_void_to_null'; - @FailingTest( - issue: 'https://github.com/dart-lang/linter/issues/4890', - reason: 'Null check operator used on a null value') test_augmentedField() async { newFile('$testPackageLibPath/a.dart', r''' import augment 'test.dart'; @@ -102,10 +99,6 @@ augment Future? get v => null; '''); } - @FailingTest( - issue: 'https://github.com/dart-lang/linter/issues/4890', - reason: - "CompileTimeErrorCode.DUPLICATE_DEFINITION [49, 1, The name 'v' is already defined.]") test_augmentedTopLevelVariable() async { newFile('$testPackageLibPath/a.dart', r''' import augment 'test.dart'; From 69b801f73f7b26adb661257ecab862eca6dcf7dd Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Wed, 10 Apr 2024 01:41:57 +0000 Subject: [PATCH 3/3] [vm/win] Release mappable snapshot once done loading. Bug: https://github.com/flutter/flutter/issues/146375 Bug: https://github.com/dart-lang/sdk/issues/55417 Change-Id: I7523579031091f9e75b2939c570d29338f33e176 TEST=ci, manually Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361985 Reviewed-by: Ryan Macnak Commit-Queue: Alexander Aprelev --- runtime/bin/elf_loader.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/bin/elf_loader.cc b/runtime/bin/elf_loader.cc index ff44319e3392..70baa9c142ad 100644 --- a/runtime/bin/elf_loader.cc +++ b/runtime/bin/elf_loader.cc @@ -289,6 +289,8 @@ bool LoadedElf::Load() { CHECK(ReadSectionStringTable()); CHECK(ReadSections()); + mappable_.reset(); + return true; }