fail_scope.carbon 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 [NameNotFound]
  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: %Bool: %Bool.type = struct_value () [template]
  25. // CHECK:STDOUT: %.1: Core.IntLiteral = int_value 32 [template]
  26. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  27. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  28. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  29. // CHECK:STDOUT: %VarScope.type: type = fn_type @VarScope [template]
  30. // CHECK:STDOUT: %VarScope: %VarScope.type = struct_value () [template]
  31. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 2 [template]
  32. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  33. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  34. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  35. // CHECK:STDOUT: %.22: <witness> = interface_witness (%Convert.14) [template]
  36. // CHECK:STDOUT: %.23: <bound method> = bound_method %.2, %Convert.14 [template]
  37. // CHECK:STDOUT: %.24: <specific function> = specific_function %.23, @Convert.2(%.1) [template]
  38. // CHECK:STDOUT: %.25: %i32 = int_value 2 [template]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: imports {
  42. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  43. // CHECK:STDOUT: .Bool = %import_ref.1
  44. // CHECK:STDOUT: .Int = %import_ref.2
  45. // CHECK:STDOUT: .ImplicitAs = %import_ref.3
  46. // CHECK:STDOUT: import Core//prelude
  47. // CHECK:STDOUT: import Core//prelude/...
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: file {
  52. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  53. // CHECK:STDOUT: .Core = imports.%Core
  54. // CHECK:STDOUT: .VarScope = %VarScope.decl
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.import = import Core
  57. // CHECK:STDOUT: %VarScope.decl: %VarScope.type = fn_decl @VarScope [template = constants.%VarScope] {
  58. // CHECK:STDOUT: %b.patt: bool = binding_pattern b
  59. // CHECK:STDOUT: %b.param_patt: bool = value_param_pattern %b.patt, runtime_param0
  60. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  61. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  62. // CHECK:STDOUT: } {
  63. // CHECK:STDOUT: %bool.make_type: init type = call constants.%Bool() [template = bool]
  64. // CHECK:STDOUT: %.loc11_16.1: type = value_of_initializer %bool.make_type [template = bool]
  65. // CHECK:STDOUT: %.loc11_16.2: type = converted %bool.make_type, %.loc11_16.1 [template = bool]
  66. // CHECK:STDOUT: %.loc11_25.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  67. // CHECK:STDOUT: %int.make_type_signed.loc11: init type = call constants.%Int(%.loc11_25.1) [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc11_25.2: type = value_of_initializer %int.make_type_signed.loc11 [template = constants.%i32]
  69. // CHECK:STDOUT: %.loc11_25.3: type = converted %int.make_type_signed.loc11, %.loc11_25.2 [template = constants.%i32]
  70. // CHECK:STDOUT: %b.param: bool = value_param runtime_param0
  71. // CHECK:STDOUT: %b: bool = bind_name b, %b.param
  72. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  73. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @VarScope(%b.param_patt: bool) -> %i32 {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: %b.ref: bool = name_ref b, %b
  80. // CHECK:STDOUT: if %b.ref br !if.then else br !if.else
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: !if.then:
  83. // CHECK:STDOUT: %.loc13_12.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  84. // CHECK:STDOUT: %int.make_type_signed.loc13: init type = call constants.%Int(%.loc13_12.1) [template = constants.%i32]
  85. // CHECK:STDOUT: %.loc13_12.2: type = value_of_initializer %int.make_type_signed.loc13 [template = constants.%i32]
  86. // CHECK:STDOUT: %.loc13_12.3: type = converted %int.make_type_signed.loc13, %.loc13_12.2 [template = constants.%i32]
  87. // CHECK:STDOUT: %n.var: ref %i32 = var n
  88. // CHECK:STDOUT: %n: ref %i32 = bind_name n, %n.var
  89. // CHECK:STDOUT: %.loc13_18: Core.IntLiteral = int_value 2 [template = constants.%.2]
  90. // CHECK:STDOUT: %.loc13_19.1: %Convert.type.2 = interface_witness_access constants.%.22, element0 [template = constants.%Convert.14]
  91. // CHECK:STDOUT: %.loc13_19.2: <bound method> = bound_method %.loc13_18, %.loc13_19.1 [template = constants.%.23]
  92. // CHECK:STDOUT: %.loc13_19.3: <specific function> = specific_function %.loc13_19.2, @Convert.2(constants.%.1) [template = constants.%.24]
  93. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc13_19.3(%.loc13_18) [template = constants.%.25]
  94. // CHECK:STDOUT: %.loc13_19.4: init %i32 = converted %.loc13_18, %int.convert_checked [template = constants.%.25]
  95. // CHECK:STDOUT: assign %n.var, %.loc13_19.4
  96. // CHECK:STDOUT: %n.ref.loc14: ref %i32 = name_ref n, %n
  97. // CHECK:STDOUT: %.loc14: %i32 = bind_value %n.ref.loc14
  98. // CHECK:STDOUT: return %.loc14
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: !if.else:
  101. // CHECK:STDOUT: %n.ref.loc19: <error> = name_ref n, <error> [template = <error>]
  102. // CHECK:STDOUT: return <error>
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: