Skip to content

Commit 7f96069

Browse files
authored
Add some tests for constraints depending on resolving other constraints (#5885)
Questions of what should be possible are raised in #5884 This provides the examples from the issue as test cases.
1 parent ae16014 commit 7f96069

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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/facet_types.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/early_rewrites.carbon
10+
// TIP: To dump output, run:
11+
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/early_rewrites.carbon
12+
13+
// Tests where `ImplWitnessAccess` on the RHS of a rewrite constraint is used in
14+
// other constraints within the same facet type in ways that require the RHS to
15+
// be evaluated to a concrete value before the facet type is resolved (such as
16+
// by passing it as a parameter to a generic class).
17+
18+
// --- nested_constraint_visible_in_type_parameter.carbon
19+
library "[[@TEST_NAME]]";
20+
21+
interface Z {
22+
let Z1:! type;
23+
let Z2:! type;
24+
}
25+
26+
class C(T:! Z where .Z1 = ()) {}
27+
28+
interface J {
29+
let J1:! (Z where .Z1 = ()) where .Z2 = C(.Self);
30+
}
31+
32+
// --- todo_earlier_constraint_visible_in_type_parameter.carbon
33+
library "[[@TEST_NAME]]";
34+
35+
interface Z {
36+
let Z1:! type;
37+
let Z2:! type;
38+
}
39+
40+
class C(T:! Z where .Z1 = ()) {}
41+
42+
// TODO: Should this pass? Or do we need a `where` between .Z1 and .Z2 to make
43+
// .Z1's value visible to .Z2?
44+
// See https://github.com/carbon-language/carbon-lang/issues/5884.
45+
interface J {
46+
let J1:! Z where .Z1 = () and .Z2 = C(.Self);
47+
}
48+
49+
// --- todo_later_constraint_visible_in_type_parameter.carbon
50+
library "[[@TEST_NAME]]";
51+
52+
interface Z {
53+
let Z1:! type;
54+
let Z2:! type;
55+
}
56+
57+
class C(T:! Z where .Z1 = ()) {}
58+
59+
// TODO: Should this pass? Or do we need a `where` between .Z1 and .Z2 to make
60+
// .Z1's value visible to .Z2?
61+
// See https://github.com/carbon-language/carbon-lang/issues/5884.
62+
interface J {
63+
let J1:! Z where .Z2 = C(.Self) and .Z1 = ();
64+
}
65+
66+
// --- fail_todo_resolved_constraint_visible_in_type_parameter.carbon
67+
library "[[@TEST_NAME]]";
68+
69+
interface Y {
70+
let Y1:! type;
71+
}
72+
73+
interface Z {
74+
let Z1:! Y;
75+
let Z2:! type;
76+
let Z3:! type;
77+
}
78+
79+
interface Tuple {}
80+
impl () as Tuple {}
81+
class C(T:! Tuple) {}
82+
83+
// TODO: Should this pass? Or do we need a `where` between .Z2 and .Z3 to make
84+
// .Z2's value visible to .Z3?
85+
// See https://github.com/carbon-language/carbon-lang/issues/5884.
86+
interface J {
87+
// CHECK:STDERR: fail_todo_resolved_constraint_visible_in_type_parameter.carbon:[[@LINE+7]]:80: error: cannot convert type `.(Z.Z2)` into type implementing `Tuple` [ConversionFailureTypeToFacet]
88+
// CHECK:STDERR: let J1:! (Z & Y where .Y1 = ()) where .Z1 = .Self and .Z2 = .Z1.Y1 and .Z3 = C(.Z2);
89+
// CHECK:STDERR: ^~~~~~
90+
// CHECK:STDERR: fail_todo_resolved_constraint_visible_in_type_parameter.carbon:[[@LINE-9]]:9: note: initializing generic parameter `T` declared here [InitializingGenericParam]
91+
// CHECK:STDERR: class C(T:! Tuple) {}
92+
// CHECK:STDERR: ^
93+
// CHECK:STDERR:
94+
let J1:! (Z & Y where .Y1 = ()) where .Z1 = .Self and .Z2 = .Z1.Y1 and .Z3 = C(.Z2);
95+
}

0 commit comments

Comments
 (0)