mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-26 07:31:20 +00:00
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`.
51 lines
2.0 KiB
Plaintext
51 lines
2.0 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
|
|
|
|
alias a = i32;
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE+6]]:5: ERROR: Duplicate name being declared in the same scope.
|
|
// CHECK:STDERR: var a: i32 = 1;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE-4]]:7: Name is previously declared here.
|
|
// CHECK:STDERR: alias a = i32;
|
|
// CHECK:STDERR: ^
|
|
var a: i32 = 1;
|
|
|
|
var b: i32 = 2;
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE+6]]:7: ERROR: Duplicate name being declared in the same scope.
|
|
// CHECK:STDERR: alias b = i32;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR: fail_name_conflict.carbon:[[@LINE-4]]:5: Name is previously declared here.
|
|
// CHECK:STDERR: var b: i32 = 2;
|
|
// CHECK:STDERR: ^
|
|
alias b = i32;
|
|
|
|
// CHECK:STDOUT: --- fail_name_conflict.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %.1: i32 = int_literal 1 [template]
|
|
// CHECK:STDOUT: %.2: i32 = int_literal 2 [template]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace {.a = %a.loc7, .b = %b} [template]
|
|
// CHECK:STDOUT: %a.loc7: type = bind_alias a, i32 [template = i32]
|
|
// CHECK:STDOUT: %a.var: ref i32 = var a
|
|
// CHECK:STDOUT: %a.loc14: ref i32 = bind_name a, %a.var
|
|
// CHECK:STDOUT: %b.var: ref i32 = var b
|
|
// CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
|
|
// CHECK:STDOUT: %.loc23: type = bind_alias <invalid>, i32 [template = i32]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @__global_init() {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %.loc14: i32 = int_literal 1 [template = constants.%.1]
|
|
// CHECK:STDOUT: assign file.%a.var, %.loc14
|
|
// CHECK:STDOUT: %.loc16: i32 = int_literal 2 [template = constants.%.2]
|
|
// CHECK:STDOUT: assign file.%b.var, %.loc16
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|