Files
carbon-lang/core
Dana Jansens 288181453e 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;
}
```
2025-03-12 18:35:03 +00:00
..