fail_scope.carbon 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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+4]]:10: error: name `n` not found [NameNotFound]
  16. // CHECK:STDERR: return n;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR:
  19. return n;
  20. }
  21. // CHECK:STDOUT: --- fail_scope.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Bool.type: type = fn_type @Bool [template]
  25. // CHECK:STDOUT: %Bool: %Bool.type = struct_value () [template]
  26. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  27. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  28. // CHECK:STDOUT: %VarScope.type: type = fn_type @VarScope [template]
  29. // CHECK:STDOUT: %VarScope: %VarScope.type = struct_value () [template]
  30. // CHECK:STDOUT: %int_2.ecc: Core.IntLiteral = int_value 2 [template]
  31. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template]
  32. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  33. // CHECK:STDOUT: %impl_witness.d39: <witness> = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template]
  34. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  35. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template]
  36. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template]
  37. // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [template]
  38. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_2.ecc, %Convert.956 [template]
  39. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  40. // CHECK:STDOUT: %int_2.ef8: %i32 = int_value 2 [template]
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: imports {
  44. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  45. // CHECK:STDOUT: .Bool = %Core.Bool
  46. // CHECK:STDOUT: .Int = %Core.Int
  47. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  48. // CHECK:STDOUT: import Core//prelude
  49. // CHECK:STDOUT: import Core//prelude/...
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: file {
  54. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  55. // CHECK:STDOUT: .Core = imports.%Core
  56. // CHECK:STDOUT: .VarScope = %VarScope.decl
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %VarScope.decl: %VarScope.type = fn_decl @VarScope [template = constants.%VarScope] {
  60. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  61. // CHECK:STDOUT: %b.param_patt: bool = value_param_pattern %b.patt, runtime_param0
  62. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  63. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  64. // CHECK:STDOUT: } {
  65. // CHECK:STDOUT: %int_32.loc11: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  66. // CHECK:STDOUT: %i32.loc11: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  67. // CHECK:STDOUT: %b.param: bool = value_param runtime_param0
  68. // CHECK:STDOUT: %.loc11_16.1: type = splice_block %.loc11_16.3 [template = bool] {
  69. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  70. // CHECK:STDOUT: %.loc11_16.2: type = value_of_initializer %bool.make_type [template = bool]
  71. // CHECK:STDOUT: %.loc11_16.3: type = converted %bool.make_type, %.loc11_16.2 [template = bool]
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  74. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  75. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: fn @VarScope(%b.param_patt: bool) -> %i32 {
  80. // CHECK:STDOUT: !entry:
  81. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  82. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: !if.then:
  85. // CHECK:STDOUT: name_binding_decl {
  86. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  87. // CHECK:STDOUT: %.loc13_5.1: %i32 = var_pattern %n.patt
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %n.var: ref %i32 = var n
  90. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2.ecc]
  91. // CHECK:STDOUT: %impl.elem0: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956]
  92. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %int_2, %impl.elem0 [template = constants.%Convert.bound]
  93. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %bound_method, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  94. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %specific_fn(%int_2) [template = constants.%int_2.ef8]
  95. // CHECK:STDOUT: %.loc13_5.2: init %i32 = converted %int_2, %int.convert_checked [template = constants.%int_2.ef8]
  96. // CHECK:STDOUT: assign %n.var, %.loc13_5.2
  97. // CHECK:STDOUT: %.loc13_12: type = splice_block %i32.loc13 [template = constants.%i32] {
  98. // CHECK:STDOUT: %int_32.loc13: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  99. // CHECK:STDOUT: %i32.loc13: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: %n: ref %i32 = bind_name n, %n.var
  102. // CHECK:STDOUT: %n.ref.loc14: ref %i32 = name_ref n, %n
  103. // CHECK:STDOUT: %.loc14: %i32 = bind_value %n.ref.loc14
  104. // CHECK:STDOUT: return %.loc14
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !if.else:
  107. // CHECK:STDOUT: %n.ref.loc20: <error> = name_ref n, <error> [template = <error>]
  108. // CHECK:STDOUT: return <error>
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT: