mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 07:54:41 +01:00
Produce helpful diagnostics when converting to a facet fails (#5109)
When converting to a facet there are three different failure modes: 1. You provided a non-type value. Only types can convert to facets. So we tell you that we found a non-type value. 2. You provided a facet type (which has type TypeType) which does not have witnesses for the the target facet's type. So we tell you that the type `T` implements `X` but needs to implement `Y`. 2. You provided a (non-facet-type) concrete type (of type TypeType) which does not implement the target facet's type (which is a FacetType). So we tell you that we need the type to implement the FacetType but it does not. 3. You provided a FacetAccessType (which is of type TypeType also, but we special case this), whose underlying FacetType is not compatible with the target facet's type. So we tell you that we need the type to implement `X` but found a FacetAccessType `T` which implements `Y`. Closes #5027
This commit is contained in:
+3
-3
@@ -16,7 +16,7 @@ class NoParams {}
|
||||
class EmptyParams() {}
|
||||
|
||||
var v: NoParams;
|
||||
// CHECK:STDERR: fail_empty_params.carbon:[[@LINE+7]]:1: error: cannot implicitly convert value of type `NoParams` to `EmptyParams()` [ImplicitAsConversionFailure]
|
||||
// CHECK:STDERR: fail_empty_params.carbon:[[@LINE+7]]:1: error: cannot implicitly convert value of type `NoParams` to `EmptyParams()` [ConversionFailure]
|
||||
// CHECK:STDERR: var w: EmptyParams() = v;
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_empty_params.carbon:[[@LINE+4]]:1: note: type `NoParams` does not implement interface `Core.ImplicitAs(EmptyParams())` [MissingImplInMemberAccessNote]
|
||||
@@ -37,7 +37,7 @@ class Outer(T:! type) {
|
||||
var v: Outer({}*);
|
||||
|
||||
// TODO: It would be nice to include the `Outer({}*).` prefix in the name of `Inner`.
|
||||
// CHECK:STDERR: fail_nested.carbon:[[@LINE+7]]:1: error: cannot implicitly convert value of type `Outer({}*)` to `Inner({.a: i32}*)` [ImplicitAsConversionFailure]
|
||||
// CHECK:STDERR: fail_nested.carbon:[[@LINE+7]]:1: error: cannot implicitly convert value of type `Outer({}*)` to `Inner({.a: i32}*)` [ConversionFailure]
|
||||
// CHECK:STDERR: var w: Outer({}*).Inner({.a: i32}*) = v;
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_nested.carbon:[[@LINE+4]]:1: note: type `Outer({}*)` does not implement interface `Core.ImplicitAs(Inner({.a: i32}*))` [MissingImplInMemberAccessNote]
|
||||
@@ -52,7 +52,7 @@ library "[[@TEST_NAME]]";
|
||||
|
||||
class C(N:! i32) {}
|
||||
|
||||
// CHECK:STDERR: fail_int_value.carbon:[[@LINE+7]]:1: error: cannot implicitly convert value of type `()` to `C(123)` [ImplicitAsConversionFailure]
|
||||
// CHECK:STDERR: fail_int_value.carbon:[[@LINE+7]]:1: error: cannot implicitly convert value of type `()` to `C(123)` [ConversionFailure]
|
||||
// CHECK:STDERR: var v: C(123) = ();
|
||||
// CHECK:STDERR: ^~~~~~~~~~~~~
|
||||
// CHECK:STDERR: fail_int_value.carbon:[[@LINE+4]]:1: note: type `()` does not implement interface `Core.ImplicitAs(C(123))` [MissingImplInMemberAccessNote]
|
||||
|
||||
Reference in New Issue
Block a user