Skip to content

Commit 9c7e0f6

Browse files
danakjzygoloid
andauthored
Add some tests for .Self in the interface params, and comments about implied constraints (#5919)
Co-authored-by: Richard Smith <[email protected]>
1 parent 545354a commit 9c7e0f6

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
2+
// Exceptions. See /LICENSE for license information.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
//
5+
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
6+
//
7+
// AUTOUPDATE
8+
// TIP: To test this file alone, run:
9+
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/fail_todo_self_in_interface_param.carbon
10+
// TIP: To dump output, run:
11+
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/fail_todo_self_in_interface_param.carbon
12+
13+
interface I(T:! type) {
14+
let I1:! type;
15+
}
16+
17+
// @dump-sem-ir-begin
18+
// CHECK:STDERR: fail_todo_self_in_interface_param.carbon:[[@LINE+4]]:12: error: name `.Self` not found [NameNotFound]
19+
// CHECK:STDERR: fn F(T:! I(.Self) where .I1 = ()) -> T.I1 {
20+
// CHECK:STDERR: ^~~~~
21+
// CHECK:STDERR:
22+
fn F(T:! I(.Self) where .I1 = ()) -> T.I1 {
23+
return ();
24+
}
25+
// @dump-sem-ir-end

toolchain/check/testdata/facet/validate_impl_constraints.carbon

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,45 @@ fn G(T:! L) {
9090
// CHECK:STDERR:
9191
F(T);
9292
}
93+
94+
// --- fail_todo_self_in_interface_generic_param_unconstrained.carbon
95+
library "[[@TEST_NAME]]";
96+
97+
interface Z {}
98+
interface I(T:! type) {}
99+
100+
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_unconstrained.carbon:[[@LINE+4]]:12: error: name `.Self` not found [NameNotFound]
101+
// CHECK:STDERR: fn F(T:! I(.Self) where .Self impls Z) {}
102+
// CHECK:STDERR: ^~~~~
103+
// CHECK:STDERR:
104+
fn F(T:! I(.Self) where .Self impls Z) {}
105+
106+
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_unconstrained.carbon:[[@LINE+4]]:16: error: name `.Self` not found [NameNotFound]
107+
// CHECK:STDERR: fn G(T:! Z & I(.Self)) {
108+
// CHECK:STDERR: ^~~~~
109+
// CHECK:STDERR:
110+
fn G(T:! Z & I(.Self)) {
111+
F(T);
112+
}
113+
114+
// --- fail_todo_self_in_interface_generic_param_constrained.carbon
115+
library "[[@TEST_NAME]]";
116+
117+
interface Z {}
118+
interface I(T:! Z) {}
119+
120+
// Implied constraint: .Self impls Z, which is satisfied and checked at the end
121+
// of the fn signature.
122+
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_constrained.carbon:[[@LINE+4]]:12: error: name `.Self` not found [NameNotFound]
123+
// CHECK:STDERR: fn F(T:! I(.Self) where .Self impls Z) {}
124+
// CHECK:STDERR: ^~~~~
125+
// CHECK:STDERR:
126+
fn F(T:! I(.Self) where .Self impls Z) {}
127+
128+
// CHECK:STDERR: fail_todo_self_in_interface_generic_param_constrained.carbon:[[@LINE+4]]:16: error: name `.Self` not found [NameNotFound]
129+
// CHECK:STDERR: fn G(T:! Z & I(.Self)) {
130+
// CHECK:STDERR: ^~~~~
131+
// CHECK:STDERR:
132+
fn G(T:! Z & I(.Self)) {
133+
F(T);
134+
}

toolchain/check/testdata/impl/impl_assoc_const.carbon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ interface Z {
354354

355355
class C;
356356
impl C as Y {}
357+
// Implied constraint: .Self impls Y. Should be verified when finishing the impl
358+
// decl (where we know .Self is C). See:
359+
// https://discord.com/channels/655572317891461132/941071822756143115/1400953094015160370
360+
//
357361
// 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]
358362
// CHECK:STDERR: impl C as Z where .Z1 = .Self {}
359363
// CHECK:STDERR: ^~~~~
@@ -372,6 +376,9 @@ class C;
372376
impl C as Y {}
373377
impl C as Z where .Z1 = C {}
374378

379+
// Implied constraint: .Self impls Y. Should be verified against the type of the
380+
// facet value replacing T when calling F.
381+
//
375382
// 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]
376383
// CHECK:STDERR: fn F(T:! Z where .Z1 = .Self) {}
377384
// CHECK:STDERR: ^~~~~
@@ -380,6 +387,9 @@ fn F(T:! Z where .Z1 = .Self) {}
380387
fn G() {
381388
F(C);
382389

390+
// Implied constraint: .Self impls Y. Should be verified against the type of
391+
// the facet value of C when casting.
392+
//
383393
// 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]
384394
// CHECK:STDERR: C as (Z where .Z1 = .Self);
385395
// CHECK:STDERR: ^~~~~

0 commit comments

Comments
 (0)