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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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 class, mixin class, enum, or extension type
/// declaration `D` with a primary constructor (note that it cannot be a
/// `<mixinApplicationClass>`, because that kind of declaration does not
/// syntactically support primary constructors). This declaration is treated as
/// a class, mixin class, enum, respectively extension type declaration without
/// a primary constructor which is obtained as described in the following. This
/// determines the dynamic semantics of a primary constructor.
/// ...
/// If `D` is an extension type, it is a compile-time error if the primary
/// constructor that `D` contains does not have exactly one parameter.
///
/// @description Check that it is a compile-time error if an extension type does
/// not contain a primary constructor that has exactly one declaring parameter
/// which is `final`.
/// @author sgrekhov22@gmail.com

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

extension type const ET1(var int v) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET2.someName(var int v) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET3([var int v = 0]) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type const ET4.someName([var int v = 0]) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type const ET5({var int v = 0}) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET6.someName({var int v = 0}) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET7({required var int v}) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

extension type const ET8.someName({required var int v}) {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(ET1);
print(ET2);
print(ET3);
print(ET4);
print(ET5);
print(ET6);
print(ET7);
print(ET8);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 class, mixin class, enum, or extension type
/// declaration `D` with a primary constructor (note that it cannot be a
/// `<mixinApplicationClass>`, because that kind of declaration does not
/// syntactically support primary constructors). This declaration is treated as
/// a class, mixin class, enum, respectively extension type declaration without
/// a primary constructor which is obtained as described in the following. This
/// determines the dynamic semantics of a primary constructor.
/// ...
/// If `D` is an extension type, it is a compile-time error if the primary
/// constructor that `D` contains does not have exactly one parameter.
///
/// @description Check that it is not an error if an extension type contains
/// a primary constructor that has exactly one parameter.
/// @author sgrekhov22@gmail.com

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

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

extension type const ET1(final int v);

extension type const ET2({final int v = 0});

// Representation variable below is `final` by default
extension type ET3.someName([int v = 0]);

extension type const ET4._({required int v}); // It is allowed to omit `final` here

main() {
Expect.equals(1, ET1(1).v);
Expect.equals(0, ET2().v);
Expect.equals(2, ET2(v: 2).v);
Expect.equals(0, ET3.someName().v);
Expect.equals(3, ET3.someName(3).v);
Expect.equals(4, ET4._(v: 4).v);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,55 @@

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

extension type const ET1(var int v);
// ^^^
extension type const ET1();
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET2.someName(var int v);
// ^^^
extension type ET2.someName();
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET3 {
this(var int v);
// ^^^
extension type ET3(int v1, final int _);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET4 {
const this.someName(var int v);
// ^^^
extension type const ET4.someName(final int v1, final int v2);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET5 {
const this(int v);
// ^
extension type ET5(int v1, [int v2 = 0]);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

extension type ET6 {
this(int v);
// ^
extension type const ET6.someName([final int v1 = 1, final int _ = 2]);
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET7(int v1, {int v2 = 0});
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type const ET8.someName({final int v1 = 1, final int v2 = 2});
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type ET9({required int v1, required int v2});
// ^
// [analyzer] unspecified
// [cfe] unspecified

extension type const ET10.someName(int v1, {required final int v2 = 2});
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(ET1);
Expand All @@ -61,4 +73,8 @@ main() {
print(ET4);
print(ET5);
print(ET6);
print(ET7);
print(ET8);
print(ET9);
print(ET10);
}