mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:54:44 +01:00
Prevent BitAnd for facet types from matching non-type values (#5111)
Currently this test fails with trying to access a comptime function with
runtime values:
```
fn F() {
let a: J = {} as J;
let b: J = {} as J;
// CHECK:STDERR: fail_bit_and_values_no_impl.carbon:[[@LINE+7]]:3: error: non-constant call to compile-time-only function [NonConstantCallToCompTimeOnlyFunction]
// CHECK:STDERR: a & b;
// CHECK:STDERR: ^~~~~
// CHECK:STDERR: core/prelude/operators/bitwise.carbon:96:3: note: compile-time-only function declared here [CompTimeOnlyFunctionHere]
// CHECK:STDERR: fn Op[self: Self](other: Self) -> Self = "type.and";
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
a & b;
}
```
The issue is that the BitAnd impl for facet types is matching on any
value of any type:
```
impl forall [T:! type] T as BitAnd
```
What we really want is for it to match on facet types (which are type
values), which is written as:
```
impl type as BitAnd
```
After this change, the error makes more sense in the above test:
```
fn F() {
let a: J = {} as J;
let b: J = {} as J;
// CHECK:STDERR: fail_bit_and_values_no_impl.carbon:[[@LINE+4]]:3: error: cannot access member of interface `Core.BitAnd` in type `J` that does not implement that interface [MissingImplInMemberAccess]
// CHECK:STDERR: a & b;
// CHECK:STDERR: ^~~~~
// CHECK:STDERR:
a & b;
}
```
This commit is contained in:
@@ -185,7 +185,6 @@ fn CallUndefined() -> i32 {
|
||||
// CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
|
||||
// CHECK:STDOUT: %As.type.fd4: type = facet_type <@As, @As(%i32)> [concrete]
|
||||
// CHECK:STDOUT: %Convert.type.99b: type = fn_type @Convert.1, @As(%i32) [concrete]
|
||||
// CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [symbolic]
|
||||
// CHECK:STDOUT: %impl_witness.882: <witness> = impl_witness (imports.%Core.import_ref.78a), @impl.686(%int_32) [concrete]
|
||||
// CHECK:STDOUT: %Convert.type.4fd: type = fn_type @Convert.5, @impl.686(%int_32) [concrete]
|
||||
// CHECK:STDOUT: %Convert.197: %Convert.type.4fd = struct_value () [concrete]
|
||||
@@ -196,6 +195,7 @@ fn CallUndefined() -> i32 {
|
||||
// CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
|
||||
// CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
|
||||
// CHECK:STDOUT: %Defined.specific_fn: <specific function> = specific_function %Defined, @Defined(%i32) [concrete]
|
||||
// CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [symbolic]
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: imports {
|
||||
|
||||
Reference in New Issue
Block a user