Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -9,9 +9,9 @@
/// declaration S when looked up on D.
/// ...
/// - An expression of the form `.<identifier>` is a constant expression if S
/// declares a constant getter.
/// declares a corresponding static constant getter.
///
/// @description Checks that expressions of the form `'.' <identifier>` is a
/// @description Checks that an expression of the form `'.' <identifier>` is a
/// constant expression if the appropriate declaration declares a constant
/// getter with the name `<identifier>`.
/// @author sgrekhov22@gmail.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,50 @@
/// declaration S when looked up on D.
/// ...
/// - An expression of the form `.<identifier>` is a constant expression if S
/// declares a constant getter.
/// declares a corresponding static constant getter.
///
/// @description Checks that it is a compile-time error to use an expressions of
/// @description Checks that it is a compile-time error to use an expression of
/// the form `'.' <identifier>` in a constant context if `<identifier>` is an
/// explicit getter declaration.
/// explicit or implicit non-constant getter declaration.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=enum-shorthands

class C {
final String value;
static C get instance => const C("C instance");
static C get instance1 => const C("C instance1");
static final C instance2 = const C("C instance2");

const C(this.value);
}

extension type const ET(String value) {
static ET get instance => const ET("ET instance");
static ET get instance1 => const ET("ET instance1");
static final ET instance2 = const ET("ET instance2");
}

main() {
const C c = .instance;
// ^
C nc1 = .instance1; // Ok
const C c1 = .instance1;
// ^
// [analyzer] unspecified
// [cfe] unspecified

const ET et = .instance;
// ^
C nc2 = .instance2;
const C c2 = .instance2;
// ^
// [analyzer] unspecified
// [cfe] unspecified

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

ET net2 = .instance2;
const ET et2 = .instance2;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
/// ...
/// - An expression of `.id(arguments)` or `.new(arguments)` is a constant
/// expression if (and only if) it occurs in a constant context, S declares a
/// constant constructor, every expression in arguments (which then occurs in
/// a constant context too) is a constant expression, and inferred type
/// arguments, if any, are all constant types.
/// corresponding constant constructor, every expression in `arguments` (which
/// then occurs in a constant context too) is a constant expression, and
/// inferred type arguments to the target class, if any, are all constant
/// types.
///
/// @description Checks that an expression of the form `'.' id(arguments)` or
/// `'.' new(arguments)` is not a constant expression if inferred type arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.

/// @assertion Declaration denoted by a type scheme A context type scheme is
/// said to denote a declaration in some cases. Not all context type schemes
/// denote a declaration.
/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.

/// @assertion Declaration denoted by a type scheme A context type scheme is
/// said to denote a declaration in some cases. Not all context type schemes
/// denote a declaration.
/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.

/// @assertion Declaration denoted by a type scheme A context type scheme is
/// said to denote a declaration in some cases. Not all context type schemes
/// denote a declaration.
/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.

/// @assertion Declaration denoted by a type scheme A context type scheme is
/// said to denote a declaration in some cases. Not all context type schemes
/// denote a declaration.
/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.

/// @assertion Declaration denoted by a type scheme A context type scheme is
/// said to denote a declaration in some cases. Not all context type schemes
/// denote a declaration.
/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.

/// @assertion Declaration denoted by a type scheme A context type scheme is
/// said to denote a declaration in some cases. Not all context type schemes
/// denote a declaration.
/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// 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.

/// @assertion Declaration denoted by a type scheme A context type scheme is
/// said to denote a declaration in some cases. Not all context type schemes
/// denote a declaration.
/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) 2025, 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.

/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
/// which currently means a class, mixin, enum or extension type declaration,
/// then `S` denotes the declaration `D`.
/// - has the form `S?` or `FutureOr<S>`, and the type scheme S denotes a
/// declaration D, then so does `S?/FutureOr<S>`. Only the "base type" of the
/// union type is considered, ensuring that a type scheme denotes at most one
/// declaration or static namespace.
/// - has any other form, including type variables, promoted type variables and
/// `_`, then the type scheme does not denote any declaration or namespace.
///
/// @description Checks that if a shorthand context type schema has one of the
/// forms `C`, `C<...>`, `C?`, or `C<...>?` and `C` is a type introduced by the
/// type declaration `D`, then the shorthand context denotes the type
/// declaration `D`. Test a class.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=enum-shorthands

import '../../Utils/expect.dart';

class C<T> {
T value;
C(this.value);
C.id(this.value);
factory C.f(T t) = C;

static C<int> get staticGetter => C(4);
static C<X> staticMethod<X>(X x) => C<X>(x);
static C<String> instance = C("one");
}

main() {
C? c1 = .new(1);
Expect.equals(1, c1.value);

C? c2 = .id(2);
Expect.equals(2, c2.value);

C<int>? c3 = .f(3);
Expect.equals(3, c3.value);

C<int>? c4 = .staticGetter;
Expect.equals(4, c4.value);

C? c5 = .staticGetter;
Expect.equals(4, c5.value);

C<int>? c6 = .staticMethod<int>(6);
Expect.equals(6, c6.value);

C? c7 = .staticMethod<int>(7);
Expect.equals(7, c7.value);

C<String>? c8 = .instance;
Expect.equals("one", c8.value);

C? c9 = .instance;
Expect.equals("one", c9.value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2025, 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.

/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
/// which currently means a class, mixin, enum or extension type declaration,
/// then `S` denotes the declaration `D`.
/// - has the form `S?` or `FutureOr<S>`, and the type scheme S denotes a
/// declaration D, then so does `S?/FutureOr<S>`. Only the "base type" of the
/// union type is considered, ensuring that a type scheme denotes at most one
/// declaration or static namespace.
/// - has any other form, including type variables, promoted type variables and
/// `_`, then the type scheme does not denote any declaration or namespace.
///
/// @description Checks that if a shorthand context type schema has one of the
/// forms `FutureOr<C>`, `FutureOr<C<...>>`, `FutureOr<C>?`,
/// `FutureOr<C<...>>?`, `FutureOr<C?>`, `FutureOr<C<...>?>`, `FutureOr<C?>?` or
/// `FutureOr<C<...>?>?` and `C` is a type introduced by the type declaration
/// `D`, then the shorthand context denotes the type declaration `D`. Test a
/// class.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=enum-shorthands

import 'dart:async';
import '../../Utils/expect.dart';

class C<T> {
T value;
C(this.value);
C.id(this.value);
factory C.f(T t) = C;

static C<int> get staticGetter => C(4);
static C<X> staticMethod<X>(X x) => C<X>(x);
static C<String> instance = C("one");
}

main() async {
FutureOr<C?>? c1 = .new(1);
Expect.equals(1, (await c1)?.value);

FutureOr<C?>? c2 = .id(2);
Expect.equals(2, (await c2)?.value);

FutureOr<C<int>?>? c3 = .f(3);
Expect.equals(3, (await c3)?.value);

FutureOr<C<int>?>? c4 = .staticGetter;
Expect.equals(4, (await c4)?.value);

FutureOr<C?>? c5 = .staticGetter;
Expect.equals(4, (await c5)?.value);

FutureOr<C<int>?>? c6 = .staticMethod<int>(6);
Expect.equals(6, (await c6)?.value);

FutureOr<C?>? c7 = .staticMethod<int>(7);
Expect.equals(7, (await c7)?.value);

FutureOr<C<String>?>? c8 = .instance;
Expect.equals("one", (await c8)?.value);

FutureOr<C?>? c9 = .instance;
Expect.equals("one", (await c9)?.value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2025, 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.

/// @assertion A context type scheme is said to denote a declaration in some
/// cases. Not all context type schemes denote a declaration.
/// If a type scheme `S`:
/// - has the form `C` or `C<typeArgs>` where `C` is a type introduced by a
/// declaration `D` which must therefore be a type-introducing declaration,
/// which currently means a class, mixin, enum or extension type declaration,
/// then `S` denotes the declaration `D`.
/// - has the form `S?` or `FutureOr<S>`, and the type scheme S denotes a
/// declaration D, then so does `S?/FutureOr<S>`. Only the "base type" of the
/// union type is considered, ensuring that a type scheme denotes at most one
/// declaration or static namespace.
/// - has any other form, including type variables, promoted type variables and
/// `_`, then the type scheme does not denote any declaration or namespace.
///
/// @description Checks that if a shorthand context type schema has one of the
/// forms `C`, `C<...>`, `C?`, or `C<...>?` and `C` is a type introduced by the
/// type declaration `D`, then the shorthand context denotes the type
/// declaration `D`. Test a mixin.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=enum-shorthands

import '../../Utils/expect.dart';

class C<T> {
T value;
C(this.value);
}

mixin M<T> on C<T> {
static M<int> get staticGetter => MC(1);
static M<X> staticMethod<X>(X x) => MC<X>(x);
static M<String> instance = MC("one");

@override
bool operator ==(Object other) {
if (other is C) {
return value == other.value;
}
return false;
}
}

class MC<T> = C<T> with M<T>;

main() {
M<int>? m1 = .staticGetter;
Expect.equals(MC(1), m1);

M? m2 = .staticGetter;
Expect.equals(MC(1), m2);

M<int>? m3 = .staticMethod<int>(3);
Expect.equals(MC(3), m3);

M? m4 = .staticMethod<int>(4);
Expect.equals(MC(4), m4);

M<String>? m5 = .instance;
Expect.equals(MC("one"), m5);

M? m6 = .instance;
Expect.equals(MC("one"), m6);
}
Loading
Loading