Files
carbon-lang/toolchain/check/testdata/class/fail_self.carbon
T
fdb188ccfd Implement unused pattern bindings, continued (#6518)
Implementation of unused pattern bindings #2022, continued.

Whereas previous PR #6460 took care of parsing, and PR #6479 prepared
the stage by using _ in some test cases, this PR has the the actual
implementation, using a simple dataflow analysis.

---------

Co-authored-by: Burak Emir <bqe@google.com>
Co-authored-by: jonmeow <jperkins@google.com>
2026-02-19 23:33:36 +00:00

63 lines
2.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/convert.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_self.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_self.carbon
class Class {
// CHECK:STDERR: fail_self.carbon:[[@LINE+4]]:8: error: `self` can only be declared in an implicit parameter list [SelfOutsideImplicitParamList]
// CHECK:STDERR: fn F(self: Self);
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR:
fn F(self: Self);
fn G() -> Self;
}
// CHECK:STDERR: fail_self.carbon:[[@LINE+4]]:19: error: `self` can only be declared in an implicit parameter list [SelfOutsideImplicitParamList]
// CHECK:STDERR: fn Class.F(unused self: Self) {
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR:
fn Class.F(unused self: Self) {
}
fn Class.G() -> Self {
// CHECK:STDERR: fail_self.carbon:[[@LINE+4]]:7: error: `self` can only be declared in an implicit parameter list [SelfOutsideImplicitParamList]
// CHECK:STDERR: var self: Self;
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR:
var self: Self;
// CHECK:STDERR: fail_self.carbon:[[@LINE+7]]:10: error: cannot copy value of type `Class` [CopyOfUncopyableType]
// CHECK:STDERR: return self;
// CHECK:STDERR: ^~~~
// CHECK:STDERR: fail_self.carbon:[[@LINE+4]]:10: note: type `Class` does not implement interface `Core.Copy` [MissingImplInMemberAccessNote]
// CHECK:STDERR: return self;
// CHECK:STDERR: ^~~~
// CHECK:STDERR:
return self;
}
class WrongSelf {
fn F[self: Class]();
}
fn CallWrongSelf(ws: WrongSelf) {
// CHECK:STDERR: fail_self.carbon:[[@LINE+10]]:3: error: cannot implicitly convert expression of type `WrongSelf` to `Class` [ConversionFailure]
// CHECK:STDERR: ws.F();
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_self.carbon:[[@LINE+7]]:3: note: type `WrongSelf` does not implement interface `Core.ImplicitAs(Class)` [MissingImplInMemberAccessNote]
// CHECK:STDERR: ws.F();
// CHECK:STDERR: ^~
// CHECK:STDERR: fail_self.carbon:[[@LINE-10]]:8: note: initializing function parameter [InCallToFunctionParam]
// CHECK:STDERR: fn F[self: Class]();
// CHECK:STDERR: ^~~~~~~~~~~
// CHECK:STDERR:
ws.F();
}