shadowing.carbon 1.4 KB

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