Skip to content

Commit d16bc3a

Browse files
Add sample language tests for valueClass feature
Add experimental_flag protection Change-Id: I0dc83fd544beb58dce5631a2a80d4d9321e866ca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155607 Commit-Queue: Javier López-Contreras <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent b7d139a commit d16bc3a

5 files changed

+70
-0
lines changed

tests/language/language.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ switch/case_warn_test: Skip # Analyzer only, see language_analyzer2.status
77

88
[ $compiler != fasta ]
99
nonfunction_type_aliases/*: Skip # github.com/dart-lang/language/issues/115
10+
value_class/*: Skip # Internship, jlcontreras
1011

1112
[ $compiler == none ]
1213
invalid_returns/*: Skip # https://github.com/dart-lang/sdk/issues/34013
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// A value class will automatically create an empty constructor if there is none yet
6+
7+
const String valueClass = "valueClass";
8+
9+
@valueClass
10+
class Animal {
11+
final int numberOfLegs;
12+
}
13+
14+
main() {
15+
var cat = Animal(numberOfLegs: 4);
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Equals operator == by value should be implicitly created
6+
7+
import 'package:expect/expect.dart';
8+
9+
// A value class will automatically create an == operator if there is none yet
10+
11+
const String valueClass = "valueClass";
12+
13+
@valueClass
14+
class Animal {
15+
final int numberOfLegs;
16+
}
17+
18+
main() {
19+
var cat = Animal(numberOfLegs: 4);
20+
var dog = Animal(numberOfLegs: 4);
21+
var human = Animal(numberOfLegs: 2);
22+
23+
Expect.equals(true, cat == dog);
24+
Expect.equals(false, cat == human);
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// It is a compile-time error if a value class has a non-final instance variable.
6+
7+
const String valueClass = "valueClass";
8+
9+
@valueClass
10+
class Animal {
11+
int numberOfLegs;
12+
//^
13+
// [cfe] unspecified
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// Value classes are always leaves in the tree of types
6+
7+
const String valueClass = "valueClass";
8+
9+
@valueClass
10+
class Animal {}
11+
12+
class Cat implements Animal {}
13+
// ^^^^^^
14+
// [cfe] unspecified

0 commit comments

Comments
 (0)