Files
carbon-lang/toolchain/check/testdata/index/fail_invalid_base.carbon
T
Richard Smith 5ccee62918 Add name_reference SemIR node for references to names. (#3260)
Also add `name_reference_untyped` for references to non-first-class
names without types, which currently covers namespaces and functions.

This improves the fidelity of the SemIR representation, and fixes some
issues where we would use the wrong location for nodes and diagnostics
downstream of a name reference.

We're still missing a representation for dotted name expressions, such
as `Namespace.Function`, and we don't use the `untyped` node as an
operand of any other node yet.
2023-10-05 01:15:53 +00:00

59 lines
2.5 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
// TODO: The errors here are in bad locations. We should build a SemIR
// representation for a reference to a name so that we can track the location
// properly.
namespace N;
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+3]]:14: ERROR: Expression cannot be used as a value.
// CHECK:STDERR: var a: i32 = N[0];
// CHECK:STDERR: ^
var a: i32 = N[0];
fn F();
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+3]]:14: ERROR: Expression cannot be used as a value.
// CHECK:STDERR: var b: i32 = F[1];
// CHECK:STDERR: ^
var b: i32 = F[1];
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+3]]:32: ERROR: `{.a: i32, .b: i32}` does not support indexing.
// CHECK:STDERR: var c: i32 = {.a = 1, .b = 2}[0];
// CHECK:STDERR: ^
var c: i32 = {.a = 1, .b = 2}[0];
// CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+3]]:34: ERROR: `type` does not support indexing.
// CHECK:STDERR: var d: i32 = {.a: i32, .b: i32}[0];
// CHECK:STDERR: ^
var d: i32 = {.a: i32, .b: i32}[0];
// CHECK:STDOUT: file "fail_invalid_base.carbon" {
// CHECK:STDOUT: %.loc11 = namespace {}
// CHECK:STDOUT: %a: ref i32 = var "a"
// CHECK:STDOUT: %N.ref = name_reference_untyped "N", %.loc11
// CHECK:STDOUT: %.loc15: i32 = int_literal 0
// CHECK:STDOUT: assign %a, <error>
// CHECK:STDOUT: %F = fn_decl @F
// CHECK:STDOUT: %b: ref i32 = var "b"
// CHECK:STDOUT: %F.ref = name_reference_untyped "F", %F
// CHECK:STDOUT: %.loc21: i32 = int_literal 1
// CHECK:STDOUT: assign %b, <error>
// CHECK:STDOUT: %c: ref i32 = var "c"
// CHECK:STDOUT: %.loc26_20: i32 = int_literal 1
// CHECK:STDOUT: %.loc26_28: i32 = int_literal 2
// CHECK:STDOUT: %.loc26_29.1: type = struct_type {.a: i32, .b: i32}
// CHECK:STDOUT: %.loc26_29.2: {.a: i32, .b: i32} = struct_literal (%.loc26_20, %.loc26_28)
// CHECK:STDOUT: %.loc26_31: i32 = int_literal 0
// CHECK:STDOUT: %.loc26_29.3: {.a: i32, .b: i32} = struct_value %.loc26_29.2, (%.loc26_20, %.loc26_28)
// CHECK:STDOUT: assign %c, <error>
// CHECK:STDOUT: %d: ref i32 = var "d"
// CHECK:STDOUT: %.loc31_31: type = struct_type {.a: i32, .b: i32}
// CHECK:STDOUT: %.loc31_33: i32 = int_literal 0
// CHECK:STDOUT: assign %d, <error>
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F();