shadowing.carbon 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. fn Main() {
  7. var x: i32 = 0;
  8. if (true) {
  9. var x: i32 = 0;
  10. // TODO: We should reject this use of the shadowed variable `x`.
  11. x = 1;
  12. }
  13. }
  14. // CHECK:STDOUT: --- shadowing.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %.1: i32 = int_literal 0 [template]
  18. // CHECK:STDOUT: %.2: bool = bool_literal true [template]
  19. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  20. // CHECK:STDOUT: }
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: file {
  23. // CHECK:STDOUT: package: <namespace> = namespace {.Main = %Main} [template]
  24. // CHECK:STDOUT: %Main: <function> = fn_decl @Main [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: fn @Main() {
  28. // CHECK:STDOUT: !entry:
  29. // CHECK:STDOUT: %x.var.loc8: ref i32 = var x
  30. // CHECK:STDOUT: %x.loc8: ref i32 = bind_name x, %x.var.loc8
  31. // CHECK:STDOUT: %.loc8: i32 = int_literal 0 [template = constants.%.1]
  32. // CHECK:STDOUT: assign %x.var.loc8, %.loc8
  33. // CHECK:STDOUT: %.loc9: bool = bool_literal true [template = constants.%.2]
  34. // CHECK:STDOUT: if %.loc9 br !if.then else br !if.else
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: !if.then:
  37. // CHECK:STDOUT: %x.var.loc10: ref i32 = var x
  38. // CHECK:STDOUT: %x.loc10: ref i32 = bind_name x, %x.var.loc10
  39. // CHECK:STDOUT: %.loc10: i32 = int_literal 0 [template = constants.%.1]
  40. // CHECK:STDOUT: assign %x.var.loc10, %.loc10
  41. // CHECK:STDOUT: %x.ref: ref i32 = name_ref x, %x.loc10
  42. // CHECK:STDOUT: %.loc13: i32 = int_literal 1 [template = constants.%.3]
  43. // CHECK:STDOUT: assign %x.ref, %.loc13
  44. // CHECK:STDOUT: br !if.else
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: !if.else:
  47. // CHECK:STDOUT: return
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: