[cfe][PrimaryConstructors] Process parameter annotations

This CL ensures the processing of parameter annotations on primary constructors.

Since primary constructors with constructor body declarations are built in two parts, the constructor is not finished when the primary constructor is built, but instead delayed to when the primary constructor body declaration is built. This conditional code path accidentally left parameter annotations unprocessed.

Fixes b/517220569

Change-Id: I8ec82283dc60a743c22cb03c041d2975e95941bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507980
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
Johnni Winther
2026-06-01 01:57:46 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 283b44e9ce
commit 0eb19fdba1
8 changed files with 164 additions and 2 deletions
+1 -2
View File
@@ -721,9 +721,8 @@ class Resolver {
internalThisVariable: internalThisVariable,
forPrimaryConstructor: true,
);
context.performBacklog(result.annotations);
}
context.performBacklog(result.annotations);
}
// Coverage-ignore(suite): Not run.
on DebugAbort {
@@ -0,0 +1,13 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
class const Self();
class Base {
Base(int x);
}
class MyComponent(@Self() final int? x) extends Base {
this : super(42);
}
@@ -0,0 +1,36 @@
library;
import self as self;
import "dart:core" as core;
class Self extends core::Object /*hasConstConstructor*/ {
const constructor •() → self::Self
: super core::Object::•()
;
static synthetic method _#new#tearOff() → self::Self
return new self::Self::•();
}
class Base extends core::Object {
constructor •(core::int x) → self::Base
: super core::Object::•()
;
static synthetic method _#new#tearOff(core::int x) → self::Base
return new self::Base::•(x);
}
class MyComponent extends self::Base {
final field core::int? x;
constructor •(@#C1 final initializing-formal core::int? x) → self::MyComponent
: self::MyComponent::x = x, super self::Base::•(42)
;
static synthetic method _#new#tearOff(core::int? x) → self::MyComponent
return new self::MyComponent::•(x);
}
constants {
#C1 = self::Self {}
}
Constructor coverage from constants:
org-dartlang-testcase:///parameter_annotation.dart:
- Self. (from org-dartlang-testcase:///parameter_annotation.dart:5:17)
- Object. (from org-dartlang-sdk:///lib/core/object.dart)
@@ -0,0 +1,36 @@
library;
import self as self;
import "dart:core" as core;
class Self extends core::Object /*hasConstConstructor*/ {
const constructor •() → self::Self
: super core::Object::•()
;
static synthetic method _#new#tearOff() → self::Self
return new self::Self::•();
}
class Base extends core::Object {
constructor •(core::int x) → self::Base
: super core::Object::•()
;
static synthetic method _#new#tearOff(core::int x) → self::Base
return new self::Base::•(x);
}
class MyComponent extends self::Base {
final field core::int? x;
constructor •(@#C1 final initializing-formal core::int? x) → self::MyComponent
: self::MyComponent::x = x, super self::Base::•(42)
;
static synthetic method _#new#tearOff(core::int? x) → self::MyComponent
return new self::MyComponent::•(x);
}
constants {
#C1 = self::Self {}
}
Constructor coverage from constants:
org-dartlang-testcase:///parameter_annotation.dart:
- Self. (from org-dartlang-testcase:///parameter_annotation.dart:5:17)
- Object. (from org-dartlang-sdk:///lib/core/object.dart)
@@ -0,0 +1,24 @@
library;
import self as self;
import "dart:core" as core;
class Self extends core::Object /*hasConstConstructor*/ {
const constructor •() → self::Self
: super core::Object::•()
;
static synthetic method _#new#tearOff() → self::Self
return new self::Self::•();
}
class Base extends core::Object {
constructor •(core::int x) → self::Base
;
static synthetic method _#new#tearOff(core::int x) → self::Base
return new self::Base::•(x);
}
class MyComponent extends self::Base {
final field core::int? x;
constructor •(final initializing-formal core::int? x) → self::MyComponent
;
static synthetic method _#new#tearOff(core::int? x) → self::MyComponent
return new self::MyComponent::•(x);
}
@@ -0,0 +1,36 @@
library;
import self as self;
import "dart:core" as core;
class Self extends core::Object /*hasConstConstructor*/ {
const constructor •() → self::Self
: super core::Object::•()
;
static synthetic method _#new#tearOff() → self::Self
return new self::Self::•();
}
class Base extends core::Object {
constructor •(core::int x) → self::Base
: super core::Object::•()
;
static synthetic method _#new#tearOff(core::int x) → self::Base
return new self::Base::•(x);
}
class MyComponent extends self::Base {
final field core::int? x;
constructor •(@#C1 final initializing-formal core::int? x) → self::MyComponent
: self::MyComponent::x = x, super self::Base::•(42)
;
static synthetic method _#new#tearOff(core::int? x) → self::MyComponent
return new self::MyComponent::•(x);
}
constants {
#C1 = self::Self {}
}
Constructor coverage from constants:
org-dartlang-testcase:///parameter_annotation.dart:
- Self. (from org-dartlang-testcase:///parameter_annotation.dart:5:17)
- Object. (from org-dartlang-sdk:///lib/core/object.dart)
@@ -0,0 +1,9 @@
class const Self();
class Base {
Base(int x);
}
class MyComponent(@Self() final int? x) extends Base {
this : super(42);
}
@@ -0,0 +1,9 @@
class Base {
Base(int x);
}
class MyComponent(@Self() final int? x) extends Base {
this : super(42);
}
class const Self();