mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add some tests for .Self in the interface params, and comments about implied constraints (#5919)
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
545354a3b4
commit
9c7e0f6bd5
@@ -0,0 +1,25 @@
|
||||
// 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/none.carbon
|
||||
//
|
||||
// AUTOUPDATE
|
||||
// TIP: To test this file alone, run:
|
||||
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/fail_todo_self_in_interface_param.carbon
|
||||
// TIP: To dump output, run:
|
||||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/fail_todo_self_in_interface_param.carbon
|
||||
|
||||
interface I(T:! type) {
|
||||
let I1:! type;
|
||||
}
|
||||
|
||||
// @dump-sem-ir-begin
|
||||
// CHECK:STDERR: fail_todo_self_in_interface_param.carbon:[[@LINE+4]]:12: error: name `.Self` not found [NameNotFound]
|
||||
// CHECK:STDERR: fn F(T:! I(.Self) where .I1 = ()) -> T.I1 {
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR:
|
||||
fn F(T:! I(.Self) where .I1 = ()) -> T.I1 {
|
||||
return ();
|
||||
}
|
||||
// @dump-sem-ir-end
|
||||
@@ -90,3 +90,45 @@ fn G(T:! L) {
|
||||
// CHECK:STDERR:
|
||||
F(T);
|
||||
}
|
||||
|
||||
// --- fail_todo_self_in_interface_generic_param_unconstrained.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
interface Z {}
|
||||
interface I(T:! type) {}
|
||||
|
||||
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_unconstrained.carbon:[[@LINE+4]]:12: error: name `.Self` not found [NameNotFound]
|
||||
// CHECK:STDERR: fn F(T:! I(.Self) where .Self impls Z) {}
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR:
|
||||
fn F(T:! I(.Self) where .Self impls Z) {}
|
||||
|
||||
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_unconstrained.carbon:[[@LINE+4]]:16: error: name `.Self` not found [NameNotFound]
|
||||
// CHECK:STDERR: fn G(T:! Z & I(.Self)) {
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR:
|
||||
fn G(T:! Z & I(.Self)) {
|
||||
F(T);
|
||||
}
|
||||
|
||||
// --- fail_todo_self_in_interface_generic_param_constrained.carbon
|
||||
library "[[@TEST_NAME]]";
|
||||
|
||||
interface Z {}
|
||||
interface I(T:! Z) {}
|
||||
|
||||
// Implied constraint: .Self impls Z, which is satisfied and checked at the end
|
||||
// of the fn signature.
|
||||
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_constrained.carbon:[[@LINE+4]]:12: error: name `.Self` not found [NameNotFound]
|
||||
// CHECK:STDERR: fn F(T:! I(.Self) where .Self impls Z) {}
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR:
|
||||
fn F(T:! I(.Self) where .Self impls Z) {}
|
||||
|
||||
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_constrained.carbon:[[@LINE+4]]:16: error: name `.Self` not found [NameNotFound]
|
||||
// CHECK:STDERR: fn G(T:! Z & I(.Self)) {
|
||||
// CHECK:STDERR: ^~~~~
|
||||
// CHECK:STDERR:
|
||||
fn G(T:! Z & I(.Self)) {
|
||||
F(T);
|
||||
}
|
||||
|
||||
@@ -354,6 +354,10 @@ interface Z {
|
||||
|
||||
class C;
|
||||
impl C as Y {}
|
||||
// Implied constraint: .Self impls Y. Should be verified when finishing the impl
|
||||
// decl (where we know .Self is C). See:
|
||||
// https://discord.com/channels/655572317891461132/941071822756143115/1400953094015160370
|
||||
//
|
||||
// CHECK:STDERR: fail_todo_period_self_impl_lookup.carbon:[[@LINE+4]]:25: error: cannot convert type `.Self` that implements `Z` into type implementing `Y` [ConversionFailureFacetToFacet]
|
||||
// CHECK:STDERR: impl C as Z where .Z1 = .Self {}
|
||||
// CHECK:STDERR: ^~~~~
|
||||
@@ -372,6 +376,9 @@ class C;
|
||||
impl C as Y {}
|
||||
impl C as Z where .Z1 = C {}
|
||||
|
||||
// Implied constraint: .Self impls Y. Should be verified against the type of the
|
||||
// facet value replacing T when calling F.
|
||||
//
|
||||
// CHECK:STDERR: fail_todo_period_self_compared_with_concrete_self.carbon:[[@LINE+4]]:24: error: cannot convert type `.Self` that implements `Z` into type implementing `Y` [ConversionFailureFacetToFacet]
|
||||
// CHECK:STDERR: fn F(T:! Z where .Z1 = .Self) {}
|
||||
// CHECK:STDERR: ^~~~~
|
||||
@@ -380,6 +387,9 @@ fn F(T:! Z where .Z1 = .Self) {}
|
||||
fn G() {
|
||||
F(C);
|
||||
|
||||
// Implied constraint: .Self impls Y. Should be verified against the type of
|
||||
// the facet value of C when casting.
|
||||
//
|
||||
// CHECK:STDERR: fail_todo_period_self_compared_with_concrete_self.carbon:[[@LINE+4]]:23: error: cannot convert type `.Self` that implements `Z` into type implementing `Y` [ConversionFailureFacetToFacet]
|
||||
// CHECK:STDERR: C as (Z where .Z1 = .Self);
|
||||
// CHECK:STDERR: ^~~~~
|
||||
|
||||
Reference in New Issue
Block a user