[M] Change in dart/sdk[main]: analyzer: Implement "do not tear-off function with @mustBeConst param...

0 views
Skip to first unread message

Samuel Rawlins (Gerrit)

unread,
Feb 16, 2026, 5:26:49 PM (yesterday) Feb 16
to Daco Harkes, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Daco Harkes

Samuel Rawlins voted and added 1 comment

Votes added by Samuel Rawlins

Commit-Queue+1

1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Samuel Rawlins . resolved

Before sending this to Dart Model folks, does this look good to you, Daco?

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I8f926d44e6b78f65a587843eb6bedf632f671af5
Gerrit-Change-Number: 481040
Gerrit-PatchSet: 2
Gerrit-Owner: Samuel Rawlins <sraw...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
Gerrit-Attention: Daco Harkes <dacoh...@google.com>
Gerrit-Comment-Date: Mon, 16 Feb 2026 22:26:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
unsatisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
1:59 AM (19 hours ago) 1:59 AM
to Samuel Rawlins, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Samuel Rawlins

Daco Harkes voted and added 1 comment

Votes added by Daco Harkes

Code-Review+1

1 comment

Patchset-level comments
Samuel Rawlins . resolved

Before sending this to Dart Model folks, does this look good to you, Daco?

Daco Harkes

Yes, pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart is exactly what I want! 🙏

Open in Gerrit

Related details

Attention is currently required from:
  • Samuel Rawlins
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I8f926d44e6b78f65a587843eb6bedf632f671af5
    Gerrit-Change-Number: 481040
    Gerrit-PatchSet: 2
    Gerrit-Owner: Samuel Rawlins <sraw...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
    Gerrit-Attention: Samuel Rawlins <sraw...@google.com>
    Gerrit-Comment-Date: Tue, 17 Feb 2026 06:59:48 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Comment-In-Reply-To: Samuel Rawlins <sraw...@google.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Konstantin Shcheglov (Gerrit)

    unread,
    12:11 PM (8 hours ago) 12:11 PM
    to Samuel Rawlins, Daco Harkes, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
    Attention needed from Samuel Rawlins

    Konstantin Shcheglov voted and added 3 comments

    Votes added by Konstantin Shcheglov

    Code-Review+1

    3 comments

    File pkg/analyzer/lib/src/error/const_argument_verifier.dart
    Line 84, Patchset 2 (Latest): var parent = node.parent;
    if (parent is PropertyAccess && parent.propertyName == node) return;
    if (parent is PrefixedIdentifier && parent.identifier == node) return;
    if (parent is DotShorthandPropertyAccess && parent.propertyName == node) {
    return;
    }
    if (parent is DotShorthandInvocation && parent.memberName == node) return;
    if (parent is MethodInvocation && parent.methodName == node) return;
    Konstantin Shcheglov . unresolved

    Because we have specific `visitX` that do it already?

    Line 191, Patchset 2 (Latest): while (parent is ParenthesizedExpression) {
    parent = parent.parent;
    }
    Konstantin Shcheglov . unresolved

    See `unParenthesized`

    File pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart
    Line 17, Patchset 2 (Latest):class TearoffWithMustBeConstParameterTest extends PubPackageResolutionTest {
    Konstantin Shcheglov . unresolved

    Tests for dot-shorthands?

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Samuel Rawlins
    Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I8f926d44e6b78f65a587843eb6bedf632f671af5
    Gerrit-Change-Number: 481040
    Gerrit-PatchSet: 2
    Gerrit-Owner: Samuel Rawlins <sraw...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
    Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
    Gerrit-Attention: Samuel Rawlins <sraw...@google.com>
    Gerrit-Comment-Date: Tue, 17 Feb 2026 17:11:11 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Samuel Rawlins (Gerrit)

    unread,
    12:45 PM (8 hours ago) 12:45 PM
    to Konstantin Shcheglov, Daco Harkes, Commit Queue, dart-analys...@google.com, rev...@dartlang.org

    Samuel Rawlins added 3 comments

    File pkg/analyzer/lib/src/error/const_argument_verifier.dart
    Line 84, Patchset 2 (Latest): var parent = node.parent;
    if (parent is PropertyAccess && parent.propertyName == node) return;
    if (parent is PrefixedIdentifier && parent.identifier == node) return;
    if (parent is DotShorthandPropertyAccess && parent.propertyName == node) {
    return;
    }
    if (parent is DotShorthandInvocation && parent.memberName == node) return;
    if (parent is MethodInvocation && parent.methodName == node) return;
    Konstantin Shcheglov . resolved

    Because we have specific `visitX` that do it already?

    Samuel Rawlins

    Correct. Let me know if you have a better way of handling this (I can add a comment). But since a SimpleIdentifier can be a tear-off itself (like a top-level function), I do have to visit SimpleIdentifier.

    Line 191, Patchset 2 (Latest): while (parent is ParenthesizedExpression) {
    parent = parent.parent;
    }
    Konstantin Shcheglov . resolved

    See `unParenthesized`

    Samuel Rawlins

    I like that helper. I wish we had a similar one that unwrapped to the parent.

    If this expression is a parenthesized expression, returns the result of unwrapping the expression inside the parentheses. Otherwise, returns this expression.

    File pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart
    Line 17, Patchset 2 (Latest):class TearoffWithMustBeConstParameterTest extends PubPackageResolutionTest {
    Konstantin Shcheglov . resolved

    Tests for dot-shorthands?

    Samuel Rawlins

    I don't think there is any way for a dot-shorthand to be torn off. This is illegal:

    ```
    class C {}

    C c1 = .new(); // OK

    C Function() c2 = .new(); // Compile-time error.

    C c3 = (.new)(); // Compile-time error.
    ```

    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I8f926d44e6b78f65a587843eb6bedf632f671af5
    Gerrit-Change-Number: 481040
    Gerrit-PatchSet: 2
    Gerrit-Owner: Samuel Rawlins <sraw...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
    Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
    Gerrit-Comment-Date: Tue, 17 Feb 2026 17:45:46 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Konstantin Shcheglov <sche...@google.com>
    satisfied_requirement
    open
    diffy

    Samuel Rawlins (Gerrit)

    unread,
    12:45 PM (8 hours ago) 12:45 PM
    to Konstantin Shcheglov, Daco Harkes, Commit Queue, dart-analys...@google.com, rev...@dartlang.org

    Samuel Rawlins voted Commit-Queue+2

    Commit-Queue+2
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    • requirement satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I8f926d44e6b78f65a587843eb6bedf632f671af5
    Gerrit-Change-Number: 481040
    Gerrit-PatchSet: 2
    Gerrit-Owner: Samuel Rawlins <sraw...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
    Gerrit-Reviewer: Samuel Rawlins <sraw...@google.com>
    Gerrit-Comment-Date: Tue, 17 Feb 2026 17:45:54 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Commit Queue (Gerrit)

    unread,
    12:46 PM (8 hours ago) 12:46 PM
    to Samuel Rawlins, Konstantin Shcheglov, Daco Harkes, dart-analys...@google.com, rev...@dartlang.org

    Commit Queue submitted the change

    Change information

    Commit message:
    analyzer: Implement "do not tear-off function with @mustBeConst parameter" warning

    Fixes https://github.com/dart-lang/sdk/issues/62472
    Change-Id: I8f926d44e6b78f65a587843eb6bedf632f671af5
    Commit-Queue: Samuel Rawlins <sraw...@google.com>
    Reviewed-by: Daco Harkes <dacoh...@google.com>
    Reviewed-by: Konstantin Shcheglov <sche...@google.com>
    Files:
    • M pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml
    • M pkg/analyzer/lib/src/diagnostic/diagnostic.g.dart
    • M pkg/analyzer/lib/src/diagnostic/diagnostic_code_values.g.dart
    • M pkg/analyzer/lib/src/error/const_argument_verifier.dart
    • M pkg/analyzer/lib/src/generated/error_verifier.dart
    • M pkg/analyzer/messages.yaml
    • A pkg/analyzer/test/src/diagnostics/tearoff_with_must_be_const_parameter_test.dart
    • M pkg/analyzer/test/src/diagnostics/test_all.dart
    Change size: M
    Delta: 8 files changed, 224 insertions(+), 0 deletions(-)
    Branch: refs/heads/main
    Submit Requirements:
    • requirement satisfiedCode-Review: +1 by Daco Harkes, +1 by Konstantin Shcheglov
    Open in Gerrit
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: merged
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: I8f926d44e6b78f65a587843eb6bedf632f671af5
    Gerrit-Change-Number: 481040
    Gerrit-PatchSet: 3
    Gerrit-Owner: Samuel Rawlins <sraw...@google.com>
    open
    diffy
    satisfied_requirement
    Reply all
    Reply to author
    Forward
    0 new messages