mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:01:05 +01:00
Per recent discussion, in `... where .A = B`, require that `B` is implicitly convertible to the type of `A` immediately, rather than treating that as part of the criteria that a type must satisfy to satisfy the resulting constraint. Extend the implementation of implicit conversion so that conversion of a type to a constraint checks that the type satisfies the constraint. As part of implementing this, stop duplicating rewrite constraints as equality constraints. Instead, when checking that a constraint is satisfied, check both its equality constraints and its rewrite constraints. This fixes an infinite recursion that would otherwise be caused by this change, and is also a necessary prerequisite for applying rewrite constraints to equality constraints, where we would otherwise collapse the implied equality constraints to a tautological `V == V` constraint. In passing, make ErrorBuilder support building the error message more incrementally and use that to improve diagnostics for mismatched values with equality constraints.
34 lines
990 B
Plaintext
34 lines
990 B
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
|
|
//
|
|
// AUTOUPDATE
|
|
// RUN: %{not} %{explorer-run}
|
|
// RUN: %{not} %{explorer-run-trace}
|
|
|
|
package ExplorerTest api;
|
|
|
|
interface X(T:! Type) {}
|
|
|
|
interface Y(T:! Type) {
|
|
let M:! X(T);
|
|
}
|
|
|
|
interface Z {
|
|
// We reject this even though it is the responsibility of the `impl as Z` to
|
|
// provide a type `N` such that `i32 is X(N)`. We might want to treat this as
|
|
// an implied constraint and allow this in the future.
|
|
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assoc_const/fail_implied_constraints.carbon:[[@LINE+1]]: could not find implementation of interface X(T = N) for i32
|
|
let N:! Y(.Self) where .M = i32;
|
|
}
|
|
|
|
impl i32 as X(i32) {}
|
|
impl i32 as Y(i32) where .M = i32 {}
|
|
impl i32 as Z where .N = i32 {}
|
|
|
|
fn F[A:! Z](a: A) -> A { return a; }
|
|
|
|
fn Main() -> i32 {
|
|
return F(0);
|
|
}
|