Skip to content

Commit fd74e49

Browse files
authored
Add tests of .Self given for an interface parameter that has constraints (#6181)
This tests that `.Self` in an interface generic parameter preserves the facet type information of the binding when returned, and allows compound member lookup back into that interface. And add a failing-todo test that `.Self` gets implied constraints which can be satisfied through `&` for the facet type `I(.Self)` is part of.
1 parent bfc4d2b commit fd74e49

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

toolchain/check/testdata/facet/period_self.carbon

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,42 @@ interface I(T:! Core.Destroy) {}
313313
// The `.Self` can see the LHS of the `where` to know `U` impls Core.Destroy.
314314
fn F(U:! Core.Destroy where .Self impls I(.Self)) {}
315315

316+
// --- fail_todo_period_self_parameter_constraint_satisfied_with_type_and.carbon
317+
library "[[@TEST_NAME]]";
318+
319+
interface I(T:! Core.Destroy) {}
320+
321+
// TODO: Implied constraints that `.Self` impls `Core.Destroy` are satisfied by
322+
// the `&` expression.
323+
//
324+
// CHECK:STDERR: fail_todo_period_self_parameter_constraint_satisfied_with_type_and.carbon:[[@LINE+7]]:25: error: cannot convert type `.Self` that implements `type` into type implementing `Core.Destroy` [ConversionFailureFacetToFacet]
325+
// CHECK:STDERR: fn F(U:! Core.Destroy & I(.Self)) {}
326+
// CHECK:STDERR: ^~~~~~~~
327+
// CHECK:STDERR: fail_todo_period_self_parameter_constraint_satisfied_with_type_and.carbon:[[@LINE-8]]:13: note: initializing generic parameter `T` declared here [InitializingGenericParam]
328+
// CHECK:STDERR: interface I(T:! Core.Destroy) {}
329+
// CHECK:STDERR: ^
330+
// CHECK:STDERR:
331+
fn F(U:! Core.Destroy & I(.Self)) {}
332+
333+
// --- fail_todo_compound_lookup_on_returned_period_self_parameter.carbon
334+
library "[[@TEST_NAME]]";
335+
336+
interface I(T:! Core.Destroy) {
337+
fn G[self: Self]() -> T;
338+
}
339+
340+
fn F[U:! Core.Destroy where .Self impls I(.Self)](u: U) {
341+
// This tests that both `I.G` is accessible and that `Destroy` is preserved;
342+
// we'd get an error for missing Destroy otherwise since G() returns an
343+
// initializing expression.
344+
345+
// CHECK:STDERR: fail_todo_compound_lookup_on_returned_period_self_parameter.carbon:[[@LINE+4]]:3: error: cannot access member of interface `I(U as Core.Destroy)` in type `U` that does not implement that interface [MissingImplInMemberAccess]
346+
// CHECK:STDERR: u.(I(U).G)().(I(U).G)().(I(U).G)();
347+
// CHECK:STDERR: ^~~~~~~~~~
348+
// CHECK:STDERR:
349+
u.(I(U).G)().(I(U).G)().(I(U).G)();
350+
}
351+
316352
// CHECK:STDOUT: --- period_self_param.carbon
317353
// CHECK:STDOUT:
318354
// CHECK:STDOUT: constants {

0 commit comments

Comments
 (0)