mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-22 21:52:39 +00:00
Instead of providing operations only for `i32`, provide them for all `iN` and `uN` types. For now, this excludes the `*Assign`, `Inc` and `Dec` interfaces, because the implementations for those are defined as Carbon functions rather than builtins, and we can't yet lower definitions for specific functions, so converting those to be generic breaks the build for our examples.
103 lines
6.9 KiB
Plaintext
103 lines
6.9 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/tuple/access/fail_non_tuple_access.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/access/fail_non_tuple_access.carbon
|
|
|
|
fn Main() {
|
|
// CHECK:STDERR: fail_non_tuple_access.carbon:[[@LINE+4]]:3: error: type `Core.IntLiteral` does not support indexing [TypeNotIndexable]
|
|
// CHECK:STDERR: 0[1];
|
|
// CHECK:STDERR: ^~~~
|
|
// CHECK:STDERR:
|
|
0[1];
|
|
|
|
var non_tuple: [i32; 2] = (5, 5);
|
|
// CHECK:STDERR: fail_non_tuple_access.carbon:[[@LINE+3]]:20: error: type `[i32; 2]` does not support tuple indexing; only tuples can be indexed that way [TupleIndexOnANonTupleType]
|
|
// CHECK:STDERR: var first: i32 = non_tuple.0;
|
|
// CHECK:STDERR: ^~~~~~~~~~~
|
|
var first: i32 = non_tuple.0;
|
|
}
|
|
|
|
// CHECK:STDOUT: --- fail_non_tuple_access.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
|
|
// CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
|
|
// CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
|
|
// CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
|
|
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
|
|
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
|
|
// CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template]
|
|
// CHECK:STDOUT: %array_type: type = array_type %int_2, %i32 [template]
|
|
// CHECK:STDOUT: %int_5.1: Core.IntLiteral = int_value 5 [template]
|
|
// CHECK:STDOUT: %tuple.type: type = tuple_type (Core.IntLiteral, Core.IntLiteral) [template]
|
|
// CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
|
|
// CHECK:STDOUT: %Convert.type.10: type = fn_type @Convert.2, @impl.1(%int_32) [template]
|
|
// CHECK:STDOUT: %Convert.10: %Convert.type.10 = struct_value () [template]
|
|
// CHECK:STDOUT: %interface.19: <witness> = interface_witness (%Convert.10) [template]
|
|
// CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_5.1, %Convert.10 [template]
|
|
// CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
|
|
// CHECK:STDOUT: %int_5.2: %i32 = int_value 5 [template]
|
|
// CHECK:STDOUT: %array: %array_type = tuple_value (%int_5.2, %int_5.2) [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
|
|
// CHECK:STDOUT: .IndexWith = %import_ref.1
|
|
// CHECK:STDOUT: .Int = %import_ref.6
|
|
// CHECK:STDOUT: .ImplicitAs = %import_ref.10
|
|
// 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: .Main = %Main.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Main() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %int_0.loc16: Core.IntLiteral = int_value 0 [template = constants.%int_0]
|
|
// CHECK:STDOUT: %int_1.loc16: Core.IntLiteral = int_value 1 [template = constants.%int_1]
|
|
// CHECK:STDOUT: %non_tuple.var: ref %array_type = var non_tuple
|
|
// CHECK:STDOUT: %non_tuple: ref %array_type = bind_name non_tuple, %non_tuple.var
|
|
// CHECK:STDOUT: %int_5.loc18_30: Core.IntLiteral = int_value 5 [template = constants.%int_5.1]
|
|
// CHECK:STDOUT: %int_5.loc18_33: Core.IntLiteral = int_value 5 [template = constants.%int_5.1]
|
|
// CHECK:STDOUT: %.loc18_34.1: %tuple.type = tuple_literal (%int_5.loc18_30, %int_5.loc18_33)
|
|
// CHECK:STDOUT: %impl.elem0.loc18_34.1: %Convert.type.2 = interface_witness_access constants.%interface.19, element0 [template = constants.%Convert.10]
|
|
// CHECK:STDOUT: %Convert.bound.loc18_34.1: <bound method> = bound_method %int_5.loc18_30, %impl.elem0.loc18_34.1 [template = constants.%Convert.bound]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc18_34.1: <specific function> = specific_function %Convert.bound.loc18_34.1, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
|
|
// CHECK:STDOUT: %int.convert_checked.loc18_34.1: init %i32 = call %Convert.specific_fn.loc18_34.1(%int_5.loc18_30) [template = constants.%int_5.2]
|
|
// CHECK:STDOUT: %.loc18_34.2: init %i32 = converted %int_5.loc18_30, %int.convert_checked.loc18_34.1 [template = constants.%int_5.2]
|
|
// CHECK:STDOUT: %int_0.loc18: Core.IntLiteral = int_value 0 [template = constants.%int_0]
|
|
// CHECK:STDOUT: %.loc18_34.3: ref %i32 = array_index %non_tuple.var, %int_0.loc18
|
|
// CHECK:STDOUT: %.loc18_34.4: init %i32 = initialize_from %.loc18_34.2 to %.loc18_34.3 [template = constants.%int_5.2]
|
|
// CHECK:STDOUT: %impl.elem0.loc18_34.2: %Convert.type.2 = interface_witness_access constants.%interface.19, element0 [template = constants.%Convert.10]
|
|
// CHECK:STDOUT: %Convert.bound.loc18_34.2: <bound method> = bound_method %int_5.loc18_33, %impl.elem0.loc18_34.2 [template = constants.%Convert.bound]
|
|
// CHECK:STDOUT: %Convert.specific_fn.loc18_34.2: <specific function> = specific_function %Convert.bound.loc18_34.2, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
|
|
// CHECK:STDOUT: %int.convert_checked.loc18_34.2: init %i32 = call %Convert.specific_fn.loc18_34.2(%int_5.loc18_33) [template = constants.%int_5.2]
|
|
// CHECK:STDOUT: %.loc18_34.5: init %i32 = converted %int_5.loc18_33, %int.convert_checked.loc18_34.2 [template = constants.%int_5.2]
|
|
// CHECK:STDOUT: %int_1.loc18: Core.IntLiteral = int_value 1 [template = constants.%int_1]
|
|
// CHECK:STDOUT: %.loc18_34.6: ref %i32 = array_index %non_tuple.var, %int_1.loc18
|
|
// CHECK:STDOUT: %.loc18_34.7: init %i32 = initialize_from %.loc18_34.5 to %.loc18_34.6 [template = constants.%int_5.2]
|
|
// CHECK:STDOUT: %.loc18_34.8: init %array_type = array_init (%.loc18_34.4, %.loc18_34.7) to %non_tuple.var [template = constants.%array]
|
|
// CHECK:STDOUT: %.loc18_35: init %array_type = converted %.loc18_34.1, %.loc18_34.8 [template = constants.%array]
|
|
// CHECK:STDOUT: assign %non_tuple.var, %.loc18_35
|
|
// CHECK:STDOUT: %first.var: ref %i32 = var first
|
|
// CHECK:STDOUT: %first: ref %i32 = bind_name first, %first.var
|
|
// CHECK:STDOUT: %non_tuple.ref: ref %array_type = name_ref non_tuple, %non_tuple
|
|
// CHECK:STDOUT: %int_0.loc22: Core.IntLiteral = int_value 0 [template = constants.%int_0]
|
|
// CHECK:STDOUT: assign %first.var, <error>
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|