shadow.carbon 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 A();
  7. namespace N;
  8. fn N.A();
  9. namespace N.M;
  10. fn N.M.B() -> i32 {
  11. // This is N.A, not package.A.
  12. A();
  13. if (true) {
  14. var A: i32 = 0;
  15. // This is the local A.
  16. // TODO: Decide if we should warn or error on the shadowing of N.A here.
  17. return A;
  18. }
  19. return 0;
  20. }
  21. // CHECK:STDOUT: --- shadow.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  25. // CHECK:STDOUT: %.2: bool = bool_literal true [template]
  26. // CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: file {
  30. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  31. // CHECK:STDOUT: .A = %A.loc7
  32. // CHECK:STDOUT: .N = %N
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: %A.loc7: <function> = fn_decl @A.1 [template] {}
  35. // CHECK:STDOUT: %N: <namespace> = namespace [template] {
  36. // CHECK:STDOUT: .A = %A.loc10
  37. // CHECK:STDOUT: .M = %M
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %A.loc10: <function> = fn_decl @A.2 [template] {}
  40. // CHECK:STDOUT: %M: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .B = %B
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %B: <function> = fn_decl @B [template] {
  44. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: fn @A.1();
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: fn @A.2();
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: fn @B() -> i32 {
  53. // CHECK:STDOUT: !entry:
  54. // CHECK:STDOUT: %A.ref.loc16: <function> = name_ref A, file.%A.loc10 [template = file.%A.loc10]
  55. // CHECK:STDOUT: %.loc16: init () = call %A.ref.loc16()
  56. // CHECK:STDOUT: %.loc17: bool = bool_literal true [template = constants.%.2]
  57. // CHECK:STDOUT: if %.loc17 br !if.then else br !if.else
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: !if.then:
  60. // CHECK:STDOUT: %A.var: ref i32 = var A
  61. // CHECK:STDOUT: %A: ref i32 = bind_name A, %A.var
  62. // CHECK:STDOUT: %.loc18: i32 = int_literal 0 [template = constants.%.3]
  63. // CHECK:STDOUT: assign %A.var, %.loc18
  64. // CHECK:STDOUT: %A.ref.loc21: ref i32 = name_ref A, %A
  65. // CHECK:STDOUT: %.loc21: i32 = bind_value %A.ref.loc21
  66. // CHECK:STDOUT: return %.loc21
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: !if.else:
  69. // CHECK:STDOUT: %.loc23: i32 = int_literal 0 [template = constants.%.3]
  70. // CHECK:STDOUT: return %.loc23
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: