mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 08:41:03 +01:00
This implements a direction decided in a [recent discussion](https://docs.google.com/document/d/1Iut5f2TQBrtBNIduF4vJYOKfw7MbS8xH_J01_Q4e6Rk/edit?resourcekey=0-mc_vh5UzrzXfU4kO-3tOjA&tab=t.0#heading=h.mas1g68xx9ct) to switch away from "template constant" when naming a constant that doesn't depend on any generic parameters, because that creates confusion with template-dependent constant values that depend on a template parameter.
143 lines
7.5 KiB
Plaintext
143 lines
7.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
|
|
// 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+4]]:14: error: type `type` does not support indexing [TypeNotIndexable]
|
|
// CHECK:STDERR: var d: i32 = {.a: i32, .b: i32}[0];
|
|
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
|
|
// CHECK:STDERR:
|
|
var d: i32 = {.a: i32, .b: i32}[0];
|
|
|
|
// CHECK:STDOUT: --- fail_invalid_base.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
|
|
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
|
|
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete]
|
|
// CHECK:STDOUT: %struct_type.a.b.cfd: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [concrete]
|
|
// CHECK:STDOUT: %struct: %struct_type.a.b.cfd = struct_value (%int_1, %int_2) [concrete]
|
|
// CHECK:STDOUT: %struct_type.a.b.501: type = struct_type {.a: %i32, .b: %i32} [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: .Int = %Core.Int
|
|
// CHECK:STDOUT: .IndexWith = %Core.IndexWith
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// 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 [concrete] {}
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
|
|
// CHECK:STDOUT: %.loc16_1: %i32 = var_pattern %a.patt
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %a.var: ref %i32 = var a
|
|
// CHECK:STDOUT: %.loc16_8: type = splice_block %i32.loc16 [concrete = constants.%i32] {
|
|
// CHECK:STDOUT: %int_32.loc16: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc16: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
|
|
// CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
|
|
// CHECK:STDOUT: %.loc23_1: %i32 = var_pattern %b.patt
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %b.var: ref %i32 = var b
|
|
// CHECK:STDOUT: %.loc23_8: type = splice_block %i32.loc23 [concrete = constants.%i32] {
|
|
// CHECK:STDOUT: %int_32.loc23: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc23: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %c.patt: %i32 = binding_pattern c
|
|
// CHECK:STDOUT: %.loc29_1: %i32 = var_pattern %c.patt
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %c.var: ref %i32 = var c
|
|
// CHECK:STDOUT: %.loc29_8: type = splice_block %i32.loc29 [concrete = constants.%i32] {
|
|
// CHECK:STDOUT: %int_32.loc29: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc29: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %c: ref %i32 = bind_name c, %c.var
|
|
// CHECK:STDOUT: name_binding_decl {
|
|
// CHECK:STDOUT: %d.patt: %i32 = binding_pattern d
|
|
// CHECK:STDOUT: %.loc35_1: %i32 = var_pattern %d.patt
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %d.var: ref %i32 = var d
|
|
// CHECK:STDOUT: %.loc35_8: type = splice_block %i32.loc35 [concrete = constants.%i32] {
|
|
// CHECK:STDOUT: %int_32.loc35: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc35: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: }
|
|
// 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 [concrete = file.%N]
|
|
// CHECK:STDOUT: %int_0.loc16: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
|
// CHECK:STDOUT: assign file.%a.var, <error>
|
|
// CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
|
// CHECK:STDOUT: %int_1.loc23: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
|
// CHECK:STDOUT: assign file.%b.var, <error>
|
|
// CHECK:STDOUT: %int_1.loc29: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
|
|
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [concrete = constants.%int_2]
|
|
// CHECK:STDOUT: %.loc29_29.1: %struct_type.a.b.cfd = struct_literal (%int_1.loc29, %int_2)
|
|
// CHECK:STDOUT: %int_0.loc29: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
|
// CHECK:STDOUT: %struct: %struct_type.a.b.cfd = struct_value (%int_1.loc29, %int_2) [concrete = constants.%struct]
|
|
// CHECK:STDOUT: %.loc29_29.2: %struct_type.a.b.cfd = converted %.loc29_29.1, %struct [concrete = constants.%struct]
|
|
// CHECK:STDOUT: assign file.%c.var, <error>
|
|
// CHECK:STDOUT: %int_32.loc35_19: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc35_19: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %int_32.loc35_28: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
|
|
// CHECK:STDOUT: %i32.loc35_28: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
|
|
// CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b.501]
|
|
// CHECK:STDOUT: %int_0.loc35: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
|
|
// CHECK:STDOUT: assign file.%d.var, <error>
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|