Files
carbon-lang/toolchain/check/testdata/index/fail_invalid_base.carbon
T
67f2c9ce26 Add a FacetValue instruction (#4545)
The new `FacetValue` instruction represents `C as I` for some type `C`
and facet type `I`. It is named `FacetValue` instead of just `Facet` to
parallel the `FacetType` instruction.

This PR uses this instruction represent the facet value `Self` in an
`impl` declaration. This instruction will be used in the future to also
support things like:

* `C as I` where `C` is a class; and
* forming a specific for a generic with a `T:! I` parameter where `T` is
being given a concrete value.

(Here `I` is an interface or other non-`type` facet type.)

Also do some renaming and add some comments to make things a bit more
clear.

* `FacetTypeAccess` -> `FacetAccessType` to clarify this is not access
of a facet type, but access of the type of a facet
* `.facet_id` -> `.facet_value_inst_id` to parallel the `FacetValue`
instruction

`FacetAccessWitness` will be in a future PR.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
2024-11-21 22:29:53 +00:00

132 lines
7.8 KiB
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
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/index/fail_invalid_base.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/index/fail_invalid_base.carbon
namespace N;
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+4]]:14: error: expression cannot be used as a value [UseOfNonExprAsValue]
// CHECK:STDERR: var a: i32 = N[0];
// CHECK:STDERR: ^
// CHECK:STDERR:
var a: i32 = N[0];
fn F();
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+4]]:14: error: expression cannot be used as a value [UseOfNonExprAsValue]
// CHECK:STDERR: var b: i32 = F[1];
// CHECK:STDERR: ^
// CHECK:STDERR:
var b: i32 = F[1];
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+4]]:14: error: type `{.a: Core.IntLiteral, .b: Core.IntLiteral}` does not support indexing [TypeNotIndexable]
// CHECK:STDERR: var c: i32 = {.a = 1, .b = 2}[0];
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
// CHECK:STDERR:
var c: i32 = {.a = 1, .b = 2}[0];
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+3]]:14: error: type `type` does not support indexing [TypeNotIndexable]
// CHECK:STDERR: var d: i32 = {.a: i32, .b: i32}[0];
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
var d: i32 = {.a: i32, .b: i32}[0];
// CHECK:STDOUT: --- fail_invalid_base.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
// CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
// CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
// CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
// CHECK:STDOUT: %.2: Core.IntLiteral = int_value 0 [template]
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
// CHECK:STDOUT: %F: %F.type = struct_value () [template]
// CHECK:STDOUT: %.3: Core.IntLiteral = int_value 1 [template]
// CHECK:STDOUT: %.4: Core.IntLiteral = int_value 2 [template]
// CHECK:STDOUT: %.5: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
// CHECK:STDOUT: %struct: %.5 = struct_value (%.3, %.4) [template]
// CHECK:STDOUT: %.11: type = struct_type {.a: %i32, .b: %i32} [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
// CHECK:STDOUT: .Int = %import_ref.1
// CHECK:STDOUT: .IndexWith = %import_ref.2
// CHECK:STDOUT: import Core//prelude
// CHECK:STDOUT: import Core//prelude/...
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Core = imports.%Core
// CHECK:STDOUT: .N = %N
// CHECK:STDOUT: .a = %a
// CHECK:STDOUT: .F = %F.decl
// CHECK:STDOUT: .b = %b
// CHECK:STDOUT: .c = %c
// CHECK:STDOUT: .d = %d
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %N: <namespace> = namespace [template] {}
// CHECK:STDOUT: %.loc16_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
// CHECK:STDOUT: %int.make_type_signed.loc16: init type = call constants.%Int(%.loc16_8.1) [template = constants.%i32]
// CHECK:STDOUT: %.loc16_8.2: type = value_of_initializer %int.make_type_signed.loc16 [template = constants.%i32]
// CHECK:STDOUT: %.loc16_8.3: type = converted %int.make_type_signed.loc16, %.loc16_8.2 [template = constants.%i32]
// CHECK:STDOUT: %a.var: ref %i32 = var a
// CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
// CHECK:STDOUT: %.loc23_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
// CHECK:STDOUT: %int.make_type_signed.loc23: init type = call constants.%Int(%.loc23_8.1) [template = constants.%i32]
// CHECK:STDOUT: %.loc23_8.2: type = value_of_initializer %int.make_type_signed.loc23 [template = constants.%i32]
// CHECK:STDOUT: %.loc23_8.3: type = converted %int.make_type_signed.loc23, %.loc23_8.2 [template = constants.%i32]
// CHECK:STDOUT: %b.var: ref %i32 = var b
// CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
// CHECK:STDOUT: %.loc29_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
// CHECK:STDOUT: %int.make_type_signed.loc29: init type = call constants.%Int(%.loc29_8.1) [template = constants.%i32]
// CHECK:STDOUT: %.loc29_8.2: type = value_of_initializer %int.make_type_signed.loc29 [template = constants.%i32]
// CHECK:STDOUT: %.loc29_8.3: type = converted %int.make_type_signed.loc29, %.loc29_8.2 [template = constants.%i32]
// CHECK:STDOUT: %c.var: ref %i32 = var c
// CHECK:STDOUT: %c: ref %i32 = bind_name c, %c.var
// CHECK:STDOUT: %.loc34_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
// CHECK:STDOUT: %int.make_type_signed.loc34: init type = call constants.%Int(%.loc34_8.1) [template = constants.%i32]
// CHECK:STDOUT: %.loc34_8.2: type = value_of_initializer %int.make_type_signed.loc34 [template = constants.%i32]
// CHECK:STDOUT: %.loc34_8.3: type = converted %int.make_type_signed.loc34, %.loc34_8.2 [template = constants.%i32]
// CHECK:STDOUT: %d.var: ref %i32 = var d
// CHECK:STDOUT: %d: ref %i32 = bind_name d, %d.var
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F();
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %N.ref: <namespace> = name_ref N, file.%N [template = file.%N]
// CHECK:STDOUT: %.loc16: Core.IntLiteral = int_value 0 [template = constants.%.2]
// CHECK:STDOUT: assign file.%a.var, <error>
// CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
// CHECK:STDOUT: %.loc23: Core.IntLiteral = int_value 1 [template = constants.%.3]
// CHECK:STDOUT: assign file.%b.var, <error>
// CHECK:STDOUT: %.loc29_20: Core.IntLiteral = int_value 1 [template = constants.%.3]
// CHECK:STDOUT: %.loc29_28: Core.IntLiteral = int_value 2 [template = constants.%.4]
// CHECK:STDOUT: %.loc29_29.1: %.5 = struct_literal (%.loc29_20, %.loc29_28)
// CHECK:STDOUT: %.loc29_31: Core.IntLiteral = int_value 0 [template = constants.%.2]
// CHECK:STDOUT: %struct: %.5 = struct_value (%.loc29_20, %.loc29_28) [template = constants.%struct]
// CHECK:STDOUT: %.loc29_29.2: %.5 = converted %.loc29_29.1, %struct [template = constants.%struct]
// CHECK:STDOUT: assign file.%c.var, <error>
// CHECK:STDOUT: %.loc34_19.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
// CHECK:STDOUT: %int.make_type_signed.loc34_19: init type = call constants.%Int(%.loc34_19.1) [template = constants.%i32]
// CHECK:STDOUT: %.loc34_19.2: type = value_of_initializer %int.make_type_signed.loc34_19 [template = constants.%i32]
// CHECK:STDOUT: %.loc34_19.3: type = converted %int.make_type_signed.loc34_19, %.loc34_19.2 [template = constants.%i32]
// CHECK:STDOUT: %.loc34_28.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
// CHECK:STDOUT: %int.make_type_signed.loc34_28: init type = call constants.%Int(%.loc34_28.1) [template = constants.%i32]
// CHECK:STDOUT: %.loc34_28.2: type = value_of_initializer %int.make_type_signed.loc34_28 [template = constants.%i32]
// CHECK:STDOUT: %.loc34_28.3: type = converted %int.make_type_signed.loc34_28, %.loc34_28.2 [template = constants.%i32]
// CHECK:STDOUT: %.loc34_31: type = struct_type {.a: %i32, .b: %i32} [template = constants.%.11]
// CHECK:STDOUT: %.loc34_33: Core.IntLiteral = int_value 0 [template = constants.%.2]
// CHECK:STDOUT: assign file.%d.var, <error>
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: