Files
carbon-lang/toolchain/check/testdata/alias/import.carbon
T
Jon Ross-Perkins 1437b0e26d Implement 'alias' with transparent semantics. (#3701)
Adds `BindAlias` with a hybrid of `BindName` and `NameRef` semantics. I
think it's slightly closer to `BindName` because it introduces a name,
so I'm going more in that direction. This also matches the need for
`bind_name_id` with imports on enclosing scopes.

Note, only things that look like a name reference are being allowed on
the RHS of `alias`. This includes builtins that look like name
references, such as `bool`, but not ones that turn into values
underneath, such as `false`.
2024-02-14 18:33:18 +00:00

62 lines
1.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
// --- a.carbon
library "a" api;
var a: i32 = 0;
alias b = a;
// --- b.carbon
library "b" api;
import library "a";
var c: i32 = b;
// CHECK:STDOUT: --- a.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: i32 = int_literal 0 [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a, .b = %b} [template]
// CHECK:STDOUT: %a.var: ref i32 = var a
// CHECK:STDOUT: %a: ref i32 = bind_name a, %a.var
// CHECK:STDOUT: %a.ref: ref i32 = name_ref a, %a
// CHECK:STDOUT: %b: ref i32 = bind_alias b, %a
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %.loc4: i32 = int_literal 0 [template = constants.%.1]
// CHECK:STDOUT: assign file.%a.var, %.loc4
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: --- b.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {.a = %import_ref.1, .b = %import_ref.2, .c = %c} [template]
// CHECK:STDOUT: %import_ref.1 = import_ref ir1, inst+2, unused
// CHECK:STDOUT: %import_ref.2: ref i32 = import_ref ir1, inst+7, used
// CHECK:STDOUT: %c.var: ref i32 = var c
// CHECK:STDOUT: %c: ref i32 = bind_name c, %c.var
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @__global_init() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %b.ref: ref i32 = name_ref b, file.%import_ref.2
// CHECK:STDOUT: %.loc6: i32 = bind_value %b.ref
// CHECK:STDOUT: assign file.%c.var, %.loc6
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: