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
61 changes: 61 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test a class.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,declaring-constructors

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

class C1 {
final int v;
const C1.foo(this.v);
const factory C1(int v) = C1.foo;
}

class C2 {
int v;
C2.foo(this.v);
factory C2(int v) => C2.foo(v + 1);
}

class C3 {
final int v;
const C3.foo(this.v);
const factory C3(int v);

augment const factory C3(int v) = C3.foo;
}

class C4 {
int v;
C4.foo(this.v);
factory C4(int v);

augment factory C4(int v) => C4.foo(v + 1);
}

main() {
var c1 = C1.new;
Expect.equals(1, c1(1).v);
var c2 = C2.new;
Expect.equals(2, c2(1).v);
var c3 = C3.new;
Expect.equals(1, c3(1).v);
var c4 = C4.new;
Expect.equals(2, c4(1).v);
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test a class and external constructors.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=declaring-constructors

import '../../Utils/static_type_helper.dart';

class C1 {
external factory C1();
}

class C2 {
external const factory C2();
}

main() {
var c1 = C1.new;
c1.expectStaticType<Exactly<C1 Function()>>();
var c2 = C2.new;
c2.expectStaticType<Exactly<C2 Function()>>();
}
57 changes: 57 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test a mixin class.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,declaring-constructors

import '../../Utils/static_type_helper.dart';

mixin class C1 {
const C1.foo();
const factory C1() = C1.foo;
}

mixin class C2 {
C2.foo();
factory C2() => C2.foo();
}

mixin class C3 {
const C3.foo();
const factory C3();

augment const factory C3() = C3.foo;
}

mixin class C4 {
C4.foo();
factory C4();

augment factory C4() => C4.foo();
}

main() {
var c1 = C1.new;
c1.expectStaticType<Exactly<C1 Function()>>();
var c2 = C2.new;
c2.expectStaticType<Exactly<C2 Function()>>();
var c3 = C3.new;
c3.expectStaticType<Exactly<C3 Function()>>();
var c4 = C4.new;
c4.expectStaticType<Exactly<C4 Function()>>();
}
37 changes: 37 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test a mixin class and external constructors.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=declaring-constructors

import '../../Utils/static_type_helper.dart';

mixin class C1 {
external factory C1();
}

mixin class C2 {
external const factory C2();
}

main() {
var c1 = C1.new;
c1.expectStaticType<Exactly<C1 Function()>>();
var c2 = C2.new;
c2.expectStaticType<Exactly<C2 Function()>>();
}
55 changes: 55 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t05.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test an extension type.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,declaring-constructors

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

extension type const ET1.foo(int v) {
const factory ET1(int v) = ET1.foo;
}

extension type ET2.foo(int v) {
factory ET2(int v) => ET2.foo(v + 1);
}

extension type const ET3._(int v) {
const ET3.foo(this.v);
const factory ET3(int v);

augment const factory ET3(int v) = ET3.foo;
}

extension type ET4._(int v) {
ET4.foo(this.v);
factory ET4(int v);

augment factory ET4(int v) => ET4.foo(v + 1);
}

main() {
var et1 = ET1.new;
Expect.equals(1, et1(1).v);
var et2 = ET2.new;
Expect.equals(2, et2(1).v);
var et3 = ET3.new;
Expect.equals(1, et3(1).v);
var et4 = ET4.new;
Expect.equals(2, et4(1).v);
}
38 changes: 38 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t06.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test an extension type and external constructors.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=declaring-constructors

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

extension type ET1._(int v) {
external factory ET1(int v);
}

extension type ET2._(int v) {
external const factory ET2(int v);
}

main() {
var et1 = ET1.new;
et1.expectStaticType<Exactly<ET1 Function(int)>>();
var et2 = ET2.new;
et2.expectStaticType<Exactly<ET2 Function(int)>>();
}
46 changes: 46 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t07.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test an enum.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=augmentations,declaring-constructors

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

enum E1 {
e0.foo(1);

final int v;
const E1.foo(this.v);
factory E1() => E1.e0;
}

enum E2 {
e0.foo(2);

final int v;
const E2.foo(this.v);
factory E2();
augment factory E2() => E2.e0;
}

main() {
var e1 = E1.new;
Expect.equals(1, e1().v);
var e2 = E2.new;
Expect.equals(2, e2().v);
}
35 changes: 35 additions & 0 deletions LanguageFeatures/Primary-constructors/grammar_A05_t08.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 Consider a factory constructor declaration of the form
/// `factory C(...` optionally starting with zero or more of the modifiers
/// `const`, `augment`, or `external`. Assume that `C` is the name of the
/// enclosing class, mixin class, enum, or extension type. In this situation,
/// the declaration declares a constructor whose name is `C`.
///
/// Without this special rule, such a declaration would declare a constructor
/// named `C.C`. With this rule it declares a constructor named `C`, which is
/// the same as today.
///
/// @description Check that in case of a factory constructor declaration of the
/// form `factory C(...` the declaration declares a constructor whose name is
/// `C`. Test an enum and external constructors.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=declaring-constructors

import '../../Utils/static_type_helper.dart';

enum E1 {
e0.foo(3);

final int v;
const E1.foo(this.v);
external factory E1();
}

main() {
var e1 = E1.new;
e1.expectStaticType<Exactly<E1 Function()>>();
}