mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 17:38:12 +00:00
The self access is important; for the test `generic_class.carbon` being added to `toolchain/check/testdata/class/destroy_calls.carbon`, it was using `%T.as.Destroy` instead of `%D.as.Destroy`, indicating the default blank impl was being used instead of the type-specific version. That test is trying to focus on the issue, but the delta is visible in a couple other files in this PR, for example `toolchain/check/testdata/class/generic/init.carbon`. I'm separately working on getting rid of the default impl, which is how I noticed this.
220 lines
6.6 KiB
Plaintext
220 lines
6.6 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/destroy_decl.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/destroy_decl.carbon
|
|
|
|
// --- self.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
fn destroy[self: Self]();
|
|
}
|
|
|
|
// --- declare_impl.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
impl as Core.Destroy;
|
|
}
|
|
|
|
// --- fail_define_impl.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_define_impl.carbon:[[@LINE+3]]:1: error: redefinition of `impl Self as Core.Destroy` [ImplRedefinition]
|
|
// CHECK:STDERR: class C {
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
class C {
|
|
// CHECK:STDERR: fail_define_impl.carbon:[[@LINE+4]]:3: note: previous definition was here [ImplPreviousDefinition]
|
|
// CHECK:STDERR: impl as Core.Destroy {
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
impl as Core.Destroy {
|
|
fn Op[addr self: Self*]() {}
|
|
}
|
|
}
|
|
|
|
// --- addr_self.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
fn destroy[addr self: Self*]();
|
|
}
|
|
|
|
// --- explicit_return.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
fn destroy[self: Self]() -> ();
|
|
}
|
|
|
|
// --- fail_class_function.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
// CHECK:STDERR: fail_class_function.carbon:[[@LINE+4]]:3: error: missing implicit `self` parameter [DestroyFunctionMissingSelf]
|
|
// CHECK:STDERR: fn destroy();
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn destroy();
|
|
}
|
|
|
|
// --- fail_extra_implicit_params_second.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
// CHECK:STDERR: fail_extra_implicit_params_second.carbon:[[@LINE+4]]:26: error: unexpected implicit parameter [DestroyFunctionUnexpectedImplicitParam]
|
|
// CHECK:STDERR: fn destroy[self: Self, T:! type]();
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
fn destroy[self: Self, T:! type]();
|
|
}
|
|
|
|
// --- fail_extra_implicit_params_first.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
// CHECK:STDERR: fail_extra_implicit_params_first.carbon:[[@LINE+4]]:14: error: unexpected implicit parameter [DestroyFunctionUnexpectedImplicitParam]
|
|
// CHECK:STDERR: fn destroy[T:! type, self: Self]();
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
fn destroy[T:! type, self: Self]();
|
|
}
|
|
|
|
// --- fail_positional_params.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
// CHECK:STDERR: fail_positional_params.carbon:[[@LINE+4]]:3: error: missing empty explicit parameter list [DestroyFunctionPositionalParams]
|
|
// CHECK:STDERR: fn destroy[self: Self];
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn destroy[self: Self];
|
|
}
|
|
|
|
// --- fail_explicit_params.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
// CHECK:STDERR: fail_explicit_params.carbon:[[@LINE+4]]:26: error: unexpected parameter [DestroyFunctionNonEmptyExplicitParams]
|
|
// CHECK:STDERR: fn destroy[self: Self](x: ());
|
|
// CHECK:STDERR: ^~~~~
|
|
// CHECK:STDERR:
|
|
fn destroy[self: Self](x: ());
|
|
}
|
|
|
|
// --- fail_return_type.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
// CHECK:STDERR: fail_return_type.carbon:[[@LINE+4]]:28: error: incorrect return type; must be unspecified or `()` [DestroyFunctionIncorrectReturnType]
|
|
// CHECK:STDERR: fn destroy[self: Self]() -> {};
|
|
// CHECK:STDERR: ^~~~~
|
|
// CHECK:STDERR:
|
|
fn destroy[self: Self]() -> {};
|
|
}
|
|
|
|
// --- fail_out_of_line_missing_params.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
|
|
class C {
|
|
fn destroy[self: Self]();
|
|
}
|
|
|
|
// CHECK:STDERR: fail_out_of_line_missing_params.carbon:[[@LINE+7]]:1: error: redeclaration differs because of missing implicit parameter list [RedeclParamListDiffers]
|
|
// CHECK:STDERR: fn C.destroy {}
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~
|
|
// CHECK:STDERR: fail_out_of_line_missing_params.carbon:[[@LINE-6]]:3: note: previously declared with implicit parameter list [RedeclParamListPrevious]
|
|
// CHECK:STDERR: fn destroy[self: Self]();
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn C.destroy {}
|
|
|
|
// --- fail_destroy_in_file_scope.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// CHECK:STDERR: fail_destroy_in_file_scope.carbon:[[@LINE+4]]:1: error: declaring `fn destroy` in non-class scope [DestroyFunctionOutsideClass]
|
|
// CHECK:STDERR: fn destroy[self: ()]();
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn destroy[self: ()]();
|
|
|
|
// --- fail_destroy_in_namespace_scope.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
namespace NS;
|
|
|
|
// CHECK:STDERR: fail_destroy_in_namespace_scope.carbon:[[@LINE+4]]:1: error: declaring `fn destroy` in non-class scope [DestroyFunctionOutsideClass]
|
|
// CHECK:STDERR: fn NS.destroy();
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn NS.destroy();
|
|
|
|
// --- fail_invalid_qualifier_with_params.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
fn destroy[self: Self]();
|
|
}
|
|
|
|
// CHECK:STDERR: fail_invalid_qualifier_with_params.carbon:[[@LINE+7]]:6: error: name qualifiers are only allowed for entities that provide a scope [QualifiedNameInNonScope]
|
|
// CHECK:STDERR: fn C.destroy[self: Self]().Foo() {}
|
|
// CHECK:STDERR: ^~~~~~~
|
|
// CHECK:STDERR: fail_invalid_qualifier_with_params.carbon:[[@LINE-6]]:3: note: referenced non-scope entity declared here [QualifiedNameNonScopeEntity]
|
|
// CHECK:STDERR: fn destroy[self: Self]();
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn C.destroy[self: Self]().Foo() {}
|
|
|
|
// --- fail_invalid_qualifier_no_params.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class C {
|
|
fn destroy[self: Self]();
|
|
}
|
|
|
|
// CHECK:STDERR: fail_invalid_qualifier_no_params.carbon:[[@LINE+7]]:6: error: name qualifiers are only allowed for entities that provide a scope [QualifiedNameInNonScope]
|
|
// CHECK:STDERR: fn C.destroy.Foo() {}
|
|
// CHECK:STDERR: ^~~~~~~
|
|
// CHECK:STDERR: fail_invalid_qualifier_no_params.carbon:[[@LINE-6]]:3: note: referenced non-scope entity declared here [QualifiedNameNonScopeEntity]
|
|
// CHECK:STDERR: fn destroy[self: Self]();
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn C.destroy.Foo() {}
|
|
|
|
// --- fail_return_type_after_no_params.carbon
|
|
|
|
library "[[@TEST_NAME]]";
|
|
|
|
// Return type handling special-cases the "no params" case.
|
|
class C {
|
|
// CHECK:STDERR: fail_return_type_after_no_params.carbon:[[@LINE+4]]:3: error: missing implicit `self` parameter [DestroyFunctionMissingSelf]
|
|
// CHECK:STDERR: fn destroy -> ();
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
fn destroy -> ();
|
|
}
|