Files
carbon-lang/toolchain/check/testdata/var/shadowing.carbon
T
Jon Ross-Perkins 895e90e791 Start including the prelude for testing. (#3861)
- Adds an empty prelude.carbon file
- Imports that file in any non-Core package file
  - Adds --disable-prelude-import to avoid that
- Adds --exclude-dump-file-prefix to be able to hide files from dumping
- Used to hide core files (we can't do this by package name due to lex
dumps, for example)
- Restructures some tests to not rely on `i32`, particularly `alias`
tests (which rely on a name ref) and tests with no prelude.

I'm adding the framework for switching i32 to calling Int32 in the
prelude, but I'm running into a separate error actually switching over.
So that *mostly* works, but isn't quite ready for prime time. However,
maybe the current state of this PR is still useful to review since it
does a lot of the infrastructure work and adds the %Core everywhere?
2024-04-07 17:11:42 +00:00

71 lines
2.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
namespace NS;
fn Main() {
var NS: i32 = 0;
NS = 1;
var x: i32 = 0;
if (true) {
var x: i32 = 0;
// TODO: We should reject this use of the shadowed variable `x`.
x = 1;
}
}
// CHECK:STDOUT: --- shadowing.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %.1: i32 = int_literal 0 [template]
// CHECK:STDOUT: %.2: i32 = int_literal 1 [template]
// CHECK:STDOUT: %.3: bool = bool_literal true [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [template] {
// CHECK:STDOUT: .Core = %Core
// CHECK:STDOUT: .NS = %NS
// CHECK:STDOUT: .Main = %Main
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
// CHECK:STDOUT: %NS: <namespace> = namespace [template] {}
// CHECK:STDOUT: %Main: <function> = fn_decl @Main [template] {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: fn @Main() {
// CHECK:STDOUT: !entry:
// CHECK:STDOUT: %NS.var: ref i32 = var NS
// CHECK:STDOUT: %NS: ref i32 = bind_name NS, %NS.var
// CHECK:STDOUT: %.loc10: i32 = int_literal 0 [template = constants.%.1]
// CHECK:STDOUT: assign %NS.var, %.loc10
// CHECK:STDOUT: %NS.ref: ref i32 = name_ref NS, %NS
// CHECK:STDOUT: %.loc11: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: assign %NS.ref, %.loc11
// CHECK:STDOUT: %x.var.loc13: ref i32 = var x
// CHECK:STDOUT: %x.loc13: ref i32 = bind_name x, %x.var.loc13
// CHECK:STDOUT: %.loc13: i32 = int_literal 0 [template = constants.%.1]
// CHECK:STDOUT: assign %x.var.loc13, %.loc13
// CHECK:STDOUT: %.loc14: bool = bool_literal true [template = constants.%.3]
// CHECK:STDOUT: if %.loc14 br !if.then else br !if.else
// CHECK:STDOUT:
// CHECK:STDOUT: !if.then:
// CHECK:STDOUT: %x.var.loc15: ref i32 = var x
// CHECK:STDOUT: %x.loc15: ref i32 = bind_name x, %x.var.loc15
// CHECK:STDOUT: %.loc15: i32 = int_literal 0 [template = constants.%.1]
// CHECK:STDOUT: assign %x.var.loc15, %.loc15
// CHECK:STDOUT: %x.ref: ref i32 = name_ref x, %x.loc15
// CHECK:STDOUT: %.loc18: i32 = int_literal 1 [template = constants.%.2]
// CHECK:STDOUT: assign %x.ref, %.loc18
// CHECK:STDOUT: br !if.else
// CHECK:STDOUT:
// CHECK:STDOUT: !if.else:
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: