Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2976. Add constant expressions tests #3024

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/// - An expression of the form `.<identifier>` is a constant expression if S
/// declares a constant getter.
///
/// @description Checks that expressions of the form `<identifier>` is a
/// @description Checks that expressions of the form `'.'<identifier>` is a
/// constant expression if the appropriate declaration declares a constant
/// getter with the name `<identifier>`.
/// @author [email protected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// declares a constant getter.
///
/// @description Checks that it is a compile-time error to use an expressions of
/// the form `.<identifier>` in a constant context if `<identifier>` is an
/// the form `'.'<identifier>` in a constant context if `<identifier>` is an
/// explicit getter declaration.
/// @author [email protected]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ extension type const ET<X, T>(int _) {
}

void foo<T>() {
C<int, T> c1 = const .new();
// ^^^^
C<int, void Function<Y extends T>()> c1 = const .new();
eernstg marked this conversation as resolved.
Show resolved Hide resolved
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
C<T, int> c2 = const .id();
// ^^^
C<void Function<Y extends T>(), int> c2 = const .id();
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
ET<int, T> et1 = const .new(0);
// ^^^^
ET<int, void Function<Y extends T>()> et1 = const .new(0);
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
ET<T, int> et2 = const .id(0);
// ^^^
ET<void Function<Y extends T>(), int> et2 = const .id(0);
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,37 @@ extension type const ET(int _) {
}

main() {
C nc1 = .id1; // Ok
const C c1 = .id1;
// ^^^^
// ^^^^
eernstg marked this conversation as resolved.
Show resolved Hide resolved
// [analyzer] unspecified
// [cfe] unspecified

C nc2 = .id1();
const C c2 = .id1();
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

C nc3 = .id2();
const C c3 = .id2();
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

ET net1 = .id1;
const ET et1 = .id1;
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

ET net2 = .id1();
const ET et2 = .id1();
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

ET net3 = .id2();
const ET et3 = .id2();
// ^^^^
// [analyzer] unspecified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ extension type const ET(int _) {
}

main() {
C nc = .id<int>(); // Ok
const C c = .id<int>();
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified

ET net = .id<int>();
const ET et = .id<int>();
// ^^^^^^^^
// [analyzer] unspecified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class C {
const C.id(this.value);
const factory C.f(String value) = C;

static const C instance = const C("C instance");
static const C? instance = const C("C instance");
}

mixin M on C {
static const M instance = const MC("M instance");
static const M? instance = const MC("M instance");
}

class MC extends C with M {
Expand All @@ -38,14 +38,14 @@ enum E {
final String value;
const E(this.value);

static const E instance = E.e0;
static const E? instance = E.e0;
}

extension type const ET(int value) {
const ET.id(this.value);
const factory ET.f(int value) = ET;

static const zero = const ET(0);
static const ET? zero = const ET(0);
}

main() {
Expand All @@ -58,16 +58,16 @@ main() {
const C c3 = const .f("three")!; // ignore: unnecessary_non_null_assertion
Expect.equals("three", c3.value);

const C c4 = .instance!; // ignore: unnecessary_non_null_assertion
const C c4 = .instance!;
eernstg marked this conversation as resolved.
Show resolved Hide resolved
Expect.equals("C instance", c4.value);

const M m = .instance!; // ignore: unnecessary_non_null_assertion
const M m = .instance!;
Expect.equals("M instance", m.value);

const E e1 = .e0!; // ignore: unnecessary_non_null_assertion
Expect.equals(e1, E.e0);

const E e2 = .instance!; // ignore: unnecessary_non_null_assertion
const E e2 = .instance!;
Expect.equals("e0", e2.value);

const ET et1 = const .new(1)!; // ignore: unnecessary_non_null_assertion
Expand All @@ -79,6 +79,6 @@ main() {
const ET et3 = const .f(3)!; // ignore: unnecessary_non_null_assertion
Expect.equals(3, et3.value);

const ET et4 = .zero!; // ignore: unnecessary_non_null_assertion
const ET et4 = .zero!;
Expect.equals(0, et4.value);
}
Loading