dart-sdk/tests/language/records/regress54375_test.dart
Nicholas Shahan 4bebe882be [ddc] Fix broken named record elements
Some named elements were colliding with existing properties on
record object instances.

Use a symbol in the runtime library for the shape and values
properties.

Ensure that the `.constructor` and `.prototype` getters are renamed
to match the expectation when compiling the access.

Add regression test for all 4 named elements.

Fixes: https://github.com/dart-lang/sdk/issues/54375
Change-Id: I7f3577455bfcff7dece6350e8c7e3ee7ffdbbac6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342703
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
2023-12-21 19:23:04 +00:00

39 lines
1 KiB
Dart

// Copyright (c) 2023, 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.
/// Regression test for https://github.com/dart-lang/sdk/issues/54375.
///
/// Records should support named elements with the names 'shape', 'values',
/// 'constructor', and 'prototype'.
import 'package:expect/expect.dart';
@pragma('dart2js:noInline')
@pragma('dart2js:assumeDynamic')
confuse(x) {
return x;
}
void main() {
var r = (shape: 123);
Expect.equals(123, r.shape);
var d = confuse(r);
Expect.equals(123, d.shape);
var r2 = (values: 'hello');
Expect.equals('hello', r2.values);
d = confuse(r2);
Expect.equals('hello', d.values);
var r3 = (constructor: Duration.zero);
Expect.equals(Duration.zero, r3.constructor);
d = confuse(r3);
Expect.equals(Duration.zero, d.constructor);
var r4 = (prototype: null);
Expect.equals(null, r4.prototype);
d = confuse(r4);
Expect.equals(null, d.prototype);
}