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

#2559. Add augmenting declarations tests #2565

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2024, 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 It is a compile-time error if:
/// - An augmenting declaration has no corresponding original declaration to
/// apply to.
///
/// @description Checks that it is a compile-time error if an augmenting
/// declaration has no corresponding original declaration to apply to
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

augment class C {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the language team (1) accepts the proposal that I hinted at in dart-lang/language#3647, or (2) tells me that we already have such a rule then this would be an error simply because it isn't in an augmentation library.

So we ought to have a test where it does occur in an augmentation library, and still there is no original declaration to augment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This might be covered by tests further down, I haven't looked at them all).

// ^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2024, 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 It is a compile-time error if:
/// - An augmenting declaration has no corresponding original declaration to
/// apply to.
///
/// @description Checks that it is a compile-time error if an augmenting
/// declaration has no corresponding original declaration to apply to
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

augment void foo() {}
// ^^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
void foo() {}
print(foo);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, 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 It is a compile-time error if:
/// - An augmenting declaration has no corresponding original declaration to
/// apply to.
///
/// @description Checks that it is not an error if an augmenting
/// declaration has a corresponding original declaration to apply to
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

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

augment class C {
int get baz => 42;
}

class C {}

main() {
Expect.equals(42, C().baz);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024, 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 It is a compile-time error if:
/// ...
/// - An augmenting declaration appears in a library before the library where
/// the original declaration occurs, according to merge order.
///
/// @description Checks that it is a compile-time error if an augmenting
/// declaration appears before non-augmenting one. Test augmented declaration in
/// a main library
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmenting_declarations_A02_t01_lib.dart';

/**/augment class C {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they accept #3647 then this would be a different error, in which case the description would need to be adjusted.

// ^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
main() {
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2024, 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 It is a compile-time error if:
/// ...
/// - An augmenting declaration appears in a library before the library where
/// the original declaration occurs, according to merge order.
///
/// @description Checks that it is a compile-time error if an augmenting
/// declaration appears before non-augmenting one. Test augmented declaration in
/// a main library
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

library augment 'augmenting_declarations_A02_t01.dart';

class C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2024, 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 It is a compile-time error if:
/// ...
/// - An augmenting declaration appears in a library before the library where
/// the original declaration occurs, according to merge order.
///
/// @description Checks that it is a compile-time error if an augmenting
/// declaration appears before non-augmenting one. Test augmented declaration in
/// an augment library
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmenting_declarations_A02_t02_lib1.dart';

main() {
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2024, 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 non-augmenting declaration must appear first before it can be
/// augmented.
///
/// @description Checks the merge order of augment libraries
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

library augment 'augmenting_declarations_A02_t02.dart';
import augment 'augmenting_declarations_A02_t02_lib2.dart';

/**/augment class C {}
// ^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2024, 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 non-augmenting declaration must appear first before it can be
/// augmented.
///
/// @description Checks the merge order of augment libraries
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

library augment 'augmenting_declarations_A02_t02_lib1.dart';

class C {}