shadowing.carbon 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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: file {
  17. // CHECK:STDOUT: package: <namespace> = namespace {.Main = %Main}
  18. // CHECK:STDOUT: %Main: <function> = fn_decl @Main
  19. // CHECK:STDOUT: }
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: fn @Main() {
  22. // CHECK:STDOUT: !entry:
  23. // CHECK:STDOUT: %x.var.loc8: ref i32 = var x
  24. // CHECK:STDOUT: %x.loc8: ref i32 = bind_name x, %x.var.loc8
  25. // CHECK:STDOUT: %.loc8: i32 = int_literal 0
  26. // CHECK:STDOUT: assign %x.var.loc8, %.loc8
  27. // CHECK:STDOUT: %.loc9: bool = bool_literal true
  28. // CHECK:STDOUT: if %.loc9 br !if.then else br !if.else
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: !if.then:
  31. // CHECK:STDOUT: %x.var.loc10: ref i32 = var x
  32. // CHECK:STDOUT: %x.loc10: ref i32 = bind_name x, %x.var.loc10
  33. // CHECK:STDOUT: %.loc10: i32 = int_literal 0
  34. // CHECK:STDOUT: assign %x.var.loc10, %.loc10
  35. // CHECK:STDOUT: %x.ref: ref i32 = name_ref x, %x.loc10
  36. // CHECK:STDOUT: %.loc13: i32 = int_literal 1
  37. // CHECK:STDOUT: assign %x.ref, %.loc13
  38. // CHECK:STDOUT: br !if.else
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: !if.else:
  41. // CHECK:STDOUT: return
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: