[L] Change in dart/sdk[main]: [tests] Declaring constructors - Tests for initializers, const, and m...

0 views
Skip to first unread message

Kallen Tu (Gerrit)

unread,
Oct 20, 2025, 9:18:58 PM (16 hours ago) Oct 20
to Erik Ernst, Commit Queue, rev...@dartlang.org
Attention needed from Erik Ernst

Kallen Tu added 1 comment

File tests/language/declaring_constructors/syntax/body_syntax_test.dart
Line 51, Patchset 1:enum EnumNamedParameters {
Kallen Tu . unresolved

Is this okay? I couldn't find information on this, but when we have a declaring constructor (body or header) for enums, is it implicitly const? Or must we explicitly declare it as such?

Open in Gerrit

Related details

Attention is currently required from:
  • Erik Ernst
Submit Requirements:
  • requirement 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: Id1c53a99a7c7748ac92ca8c4a411f762eea21a37
Gerrit-Change-Number: 456164
Gerrit-PatchSet: 3
Gerrit-Owner: Kallen Tu <kall...@google.com>
Gerrit-Reviewer: Erik Ernst <eer...@google.com>
Gerrit-Reviewer: Kallen Tu <kall...@google.com>
Gerrit-Attention: Erik Ernst <eer...@google.com>
Gerrit-Comment-Date: Tue, 21 Oct 2025 01:18:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Erik Ernst (Gerrit)

unread,
4:12 AM (9 hours ago) 4:12 AM
to Kallen Tu, Commit Queue, rev...@dartlang.org
Attention needed from Kallen Tu

Erik Ernst voted and added 16 comments

Votes added by Erik Ernst

Code-Review+1

16 comments

Patchset-level comments
File-level comment, Patchset 3 (Latest):
Erik Ernst . resolved

LGTM, with some comments.

Commit Message
Line 16, Patchset 3 (Latest):- Declaring constructors can have initializing parameters.
Erik Ernst . unresolved

I think the phrase 'initializing parameters' is ambiguous. Perhaps it means 'declaring parameters', or perhaps 'initializing formals'? 'Declaring parameters' seems to be the one that isn't mentioned elsewhere.

OK, 'initializing formals' is a rather funny phrase to use as the standard phrase to categorize `this.x`, but that's what we have and we should rename it consistently if anybody comes up with a better one. ;-)

File tests/language/declaring_constructors/body/in_body_initializer_test.dart
Line 6, Patchset 3 (Latest):// as initializing formals and super parameters, just like other constructors in
Erik Ernst . unresolved

I don't see any super parameters here. There are some in tests/language/declaring_constructors/syntax/body_syntax_test.dart so it should be fine to just avoid talking about them here.

Line 23, Patchset 3 (Latest): this(final int x) : super(x + 1);
Erik Ernst . unresolved

Interesting! This introduces a second instance variable whose name is `x`, and its getter will override the getter that reads the instance variable `x` in the superclass. It should work! But it would probably be helpful for future readers to add a comment explaining that we're doing this "waste some space in the superclass layout" trick. ;-)

Line 26, Patchset 3 (Latest):class C3 extends C1 {
Erik Ernst . unresolved

Probably `C4`.

Line 28, Patchset 3 (Latest): this(final int x) : y = x, assert(x > 0), super(x + 1);
Erik Ernst . unresolved

`final` could be omitted here and the new instance variable could have a name different from `y`, just so the more typical setup (with no instance variable shadowing) is tested as well.

Line 32, Patchset 3 (Latest): this(final int x) : assert(x > 0);
Erik Ernst . unresolved

Nit: Remove one space before `:`.

File tests/language/declaring_constructors/header/in_body_initializer_test.dart
Line 22, Patchset 3 (Latest):class C3(final int x) extends C1 {
Erik Ernst . unresolved

Might as well make this parameter non-declaring, because that's much more likely in real code than the instance variable shadowing.

Line 26, Patchset 3 (Latest):class C3(final int x) extends C1 {
Erik Ernst . unresolved

`C4`. `x` could be non-declaring again.

File tests/language/declaring_constructors/header/optional_parameter_nonconstant_default_error_test.dart
Line 8, Patchset 3 (Latest):// non-constant default values.
Erik Ernst . unresolved

Perhaps add a few words in this comment to say that this is the header case, and conversely in tests/language/declaring_constructors/body/optional_parameter_nonconstant_default_error_test.dart that it's the body case.

File tests/language/declaring_constructors/syntax/body_syntax_test.dart
Line 51, Patchset 1:enum EnumNamedParameters {
Kallen Tu . resolved

Is this okay? I couldn't find information on this, but when we have a declaring constructor (body or header) for enums, is it implicitly const? Or must we explicitly declare it as such?

Erik Ernst

A header constructor in an `enum` declaration is implicitly constant, https://github.com/dart-lang/language/blob/3911ceae94875924786c8548f94abfd3743b9080/accepted/future-releases/primary-constructors/feature-specification.md?plain=1#L957. But in the body it is required to be marked `const`, just like all other `enum` constructors in the body.

I'm afraid the current wording in the feature specification allows for the interpretation that the `const` on the declaring body constructor in an `enum` declaration can be omitted, too, but I'll fix that. ;-)

Line 54, Patchset 3 (Latest): this({final int x = 1, required var int y});
Erik Ernst . unresolved

So this one needs `const`, or an error should be expected.

Line 63, Patchset 3 (Latest): e(1, 2);
Erik Ernst . unresolved

Perhaps add a couple of other values passing one and zero actual arguments, to confirm that those parameters are actually treated as optional.

File tests/language/declaring_constructors/syntax/header_syntax_test.dart
Line 24, Patchset 3 (Latest):// Initializing parameters.
Erik Ernst . unresolved

'A declaring parameter and an initializing formal' would be clearer. Or perhaps just drop `x` entirely.

Line 37, Patchset 3 (Latest): e(x: 1, y: 2);
Erik Ernst . unresolved

Perhaps add `, e2(y: 3)`.

Line 44, Patchset 3 (Latest): e(1, 2);
Erik Ernst . unresolved

Perhaps add `, e2(3), e3()`.

Open in Gerrit

Related details

Attention is currently required from:
  • Kallen Tu
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: Id1c53a99a7c7748ac92ca8c4a411f762eea21a37
Gerrit-Change-Number: 456164
Gerrit-PatchSet: 3
Gerrit-Owner: Kallen Tu <kall...@google.com>
Gerrit-Reviewer: Erik Ernst <eer...@google.com>
Gerrit-Reviewer: Kallen Tu <kall...@google.com>
Gerrit-Attention: Kallen Tu <kall...@google.com>
Gerrit-Comment-Date: Tue, 21 Oct 2025 08:12:26 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Kallen Tu <kall...@google.com>
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages