fail_scope.carbon 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/if/fail_scope.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if/fail_scope.carbon
  10. fn VarScope(b: bool) -> i32 {
  11. if (b) {
  12. var n: i32 = 2;
  13. return n;
  14. }
  15. // CHECK:STDERR: fail_scope.carbon:[[@LINE+3]]:10: error: name `n` not found
  16. // CHECK:STDERR: return n;
  17. // CHECK:STDERR: ^
  18. return n;
  19. }
  20. // CHECK:STDOUT: --- fail_scope.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  24. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  25. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  26. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  27. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  28. // CHECK:STDOUT: %VarScope.type: type = fn_type @VarScope [template]
  29. // CHECK:STDOUT: %VarScope: %VarScope.type = struct_value () [template]
  30. // CHECK:STDOUT: %.2: i32 = int_literal 2 [template]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  35. // CHECK:STDOUT: .Bool = %import_ref.1
  36. // CHECK:STDOUT: .Int32 = %import_ref.2
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/operators
  39. // CHECK:STDOUT: import Core//prelude/types
  40. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  41. // CHECK:STDOUT: import Core//prelude/operators/as
  42. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  43. // CHECK:STDOUT: import Core//prelude/operators/comparison
  44. // CHECK:STDOUT: import Core//prelude/types/bool
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %import_ref.1: %Bool.type = import_ref Core//prelude/types/bool, inst+2, loaded [template = constants.%Bool]
  47. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: file {
  51. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  52. // CHECK:STDOUT: .Core = imports.%Core
  53. // CHECK:STDOUT: .VarScope = %VarScope.decl
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: %Core.import = import Core
  56. // CHECK:STDOUT: %VarScope.decl: %VarScope.type = fn_decl @VarScope [template = constants.%VarScope] {
  57. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  58. // CHECK:STDOUT: } {
  59. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  60. // CHECK:STDOUT: %.loc11_16.1: type = value_of_initializer %bool.make_type [template = bool]
  61. // CHECK:STDOUT: %.loc11_16.2: type = converted %bool.make_type, %.loc11_16.1 [template = bool]
  62. // CHECK:STDOUT: %b.param: bool = param b, runtime_param0
  63. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  64. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %.loc11_25.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  66. // CHECK:STDOUT: %.loc11_25.2: type = converted %int.make_type_32.loc11, %.loc11_25.1 [template = i32]
  67. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @Bool() -> type = "bool.make_type";
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @VarScope(%b: bool) -> i32 {
  76. // CHECK:STDOUT: !entry:
  77. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  78. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: !if.then:
  81. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  82. // CHECK:STDOUT: %.loc13_12.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  83. // CHECK:STDOUT: %.loc13_12.2: type = converted %int.make_type_32.loc13, %.loc13_12.1 [template = i32]
  84. // CHECK:STDOUT: %n.var: ref i32 = var n
  85. // CHECK:STDOUT: %n: ref i32 = bind_name n, %n.var
  86. // CHECK:STDOUT: %.loc13_18: i32 = int_literal 2 [template = constants.%.2]
  87. // CHECK:STDOUT: assign %n.var, %.loc13_18
  88. // CHECK:STDOUT: %n.ref.loc14: ref i32 = name_ref n, %n
  89. // CHECK:STDOUT: %.loc14: i32 = bind_value %n.ref.loc14
  90. // CHECK:STDOUT: return %.loc14
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: !if.else:
  93. // CHECK:STDOUT: %n.ref.loc19: <error> = name_ref n, <error> [template = <error>]
  94. // CHECK:STDOUT: return <error>
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT: