visitRecordLiteral method
Visit a SRecordLiteral.
Implementation
@override
Object? visitRecordLiteral(SRecordLiteral node) {
final positional = <Object?>[];
final named = <String, Object?>{};
for (final field in node.fields) {
if (field is SNamedExpression) {
final name = field.name!.label!.name;
final value = field.expression!.accept<Object?>(this);
if (named.containsKey(name)) {
throw RuntimeD4rtException(
"Record literal field '$name' specified more than once.",
);
}
named[name] = value;
} else {
// Positional field: expression
if (named.isNotEmpty) {
// As per Dart spec, positional fields must come before named fields
throw RuntimeD4rtException(
"Positional fields must come before named fields in record literal.",
);
}
positional.add(field.accept<Object?>(this));
}
}
Logger.debug("[visitRecordLiteral] Created record: ($positional, $named)");
return InterpretedRecord(positional, named);
}