Skip to content

[record_use] Completeness: record consts (record record consts) #3054

Closed

Description

@dcharkes
import 'package:meta/meta.dart' show RecordUse;

void main() {
   // Records are valid keys in a constant map in Dart.
   print(SomeClass.someStaticMethod(const {
     (1, 2): 'positional-record-key',
     ('id', name: 'gemini'): 'mixed-record-key',
   }));
 }

 class SomeClass {
   @RecordUse()
   static String someStaticMethod(Object? a) => a.runtimeType.toString();
 }

(Side note we need to report them as unsupported in the meantime #2899)

  • package:record_use
  • implement in the Dart SDK
  • tests in the Dart SDK

Activity

  1. dcharkes commented on Feb 23, 2026

    @dcharkes
    CollaboratorAuthor

    ✦ In Kernel (the Dart intermediate representation used by the VM and CFE), record constants are represented by the RecordConstant class:

    • Location: pkg/kernel/lib/src/ast/constants.dart
    • Structure:
      • positional: A List for the positional fields.
      • named: A Map<String, Constant> for the named fields, where keys are field names. The names are sorted lexicographically.
      • recordType: A RecordType object describing the runtime type of the record.

    In dart2js, record constants are represented by the RecordConstantValue class:

    • Location: pkg/compiler/lib/src/constants/values.dart
    • Structure:
      • shape: A RecordShape object that defines the record's structure (the number of positional fields and the names of the named fields).
      • values: A single List containing all field values. Positional fields come first, followed by named fields in the order specified by the
        shape.
    • Accessing fields: You use the shape to determine which indices in the values list correspond to which fields.

    We don't have a way to represent types in the recorded uses, so we'll not record the type, but we will record positional and named fields.

  2. self-assigned this
    on Feb 23, 2026
  3. moved this from Todo to In Progress in Native Assetson Feb 23, 2026
  4. moved this from In Progress to Done in Native Assetson Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions