Files
carbon-lang/toolchain/check/testdata/alias/local.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

37 lines
1.2 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
fn F() -> i32 {
var a: i32 = 0;
alias b = a;
return b;
}
// CHECK:STDOUT: --- local.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 {.F = %F} [template]
// CHECK:STDOUT: %F: <function> = fn_decl @F [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @F() -> i32 {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %a.var: ref i32 = var a
// CHECK:STDOUT: %a: ref i32 = bind_name a, %a.var
// CHECK:STDOUT: %.loc8: i32 = int_literal 0 [template = constants.%.1]
// CHECK:STDOUT: assign %a.var, %.loc8
// CHECK:STDOUT: %a.ref: ref i32 = name_ref a, %a
// CHECK:STDOUT: %b: ref i32 = bind_alias b, %a
// CHECK:STDOUT: %b.ref: ref i32 = name_ref b, %b
// CHECK:STDOUT: %.loc10: i32 = bind_value %b.ref
// CHECK:STDOUT: return %.loc10
// CHECK:STDOUT: }
// CHECK:STDOUT: