fail_scope.carbon 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/class/fail_scope.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_scope.carbon
  10. class Class {
  11. fn F() -> i32 {
  12. return 1;
  13. }
  14. }
  15. fn G() -> i32 {
  16. // CHECK:STDERR: fail_scope.carbon:[[@LINE+3]]:10: error: name `F` not found [NameNotFound]
  17. // CHECK:STDERR: return F();
  18. // CHECK:STDERR: ^
  19. return F();
  20. }
  21. // CHECK:STDOUT: --- fail_scope.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Class: type = class_type @Class [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: %F.type: type = fn_type @F [template]
  30. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  31. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  32. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  33. // CHECK:STDOUT: %.4: Core.IntLiteral = int_value 1 [template]
  34. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  35. // CHECK:STDOUT: %Convert.type.14: type = fn_type @Convert.2, @impl.1(%.1) [template]
  36. // CHECK:STDOUT: %Convert.14: %Convert.type.14 = struct_value () [template]
  37. // CHECK:STDOUT: %.24: <witness> = interface_witness (%Convert.14) [template]
  38. // CHECK:STDOUT: %.25: <bound method> = bound_method %.4, %Convert.14 [template]
  39. // CHECK:STDOUT: %.26: <specific function> = specific_function %.25, @Convert.2(%.1) [template]
  40. // CHECK:STDOUT: %.27: %i32 = int_value 1 [template]
  41. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  42. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  47. // CHECK:STDOUT: .Int = %import_ref.1
  48. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  49. // CHECK:STDOUT: import Core//prelude
  50. // CHECK:STDOUT: import Core//prelude/...
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: file {
  55. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  56. // CHECK:STDOUT: .Core = imports.%Core
  57. // CHECK:STDOUT: .Class = %Class.decl
  58. // CHECK:STDOUT: .G = %G.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core.import = import Core
  61. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  62. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  63. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  64. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  65. // CHECK:STDOUT: } {
  66. // CHECK:STDOUT: %.loc17_11.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  67. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc17_11.1) [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc17_11.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  69. // CHECK:STDOUT: %.loc17_11.3: type = converted %int.make_type_signed, %.loc17_11.2 [template = constants.%i32]
  70. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  71. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: class @Class {
  76. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  77. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  78. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  79. // CHECK:STDOUT: } {
  80. // CHECK:STDOUT: %.loc12_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  81. // CHECK:STDOUT: %int.make_type_signed: init type = call constants.%Int(%.loc12_13.1) [template = constants.%i32]
  82. // CHECK:STDOUT: %.loc12_13.2: type = value_of_initializer %int.make_type_signed [template = constants.%i32]
  83. // CHECK:STDOUT: %.loc12_13.3: type = converted %int.make_type_signed, %.loc12_13.2 [template = constants.%i32]
  84. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  85. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.2 [template = constants.%.3]
  88. // CHECK:STDOUT:
  89. // CHECK:STDOUT: !members:
  90. // CHECK:STDOUT: .Self = constants.%Class
  91. // CHECK:STDOUT: .F = %F.decl
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: fn @F() -> %i32 {
  95. // CHECK:STDOUT: !entry:
  96. // CHECK:STDOUT: %.loc13_12: Core.IntLiteral = int_value 1 [template = constants.%.4]
  97. // CHECK:STDOUT: %.loc13_13.1: %Convert.type.2 = interface_witness_access constants.%.24, element0 [template = constants.%Convert.14]
  98. // CHECK:STDOUT: %.loc13_13.2: <bound method> = bound_method %.loc13_12, %.loc13_13.1 [template = constants.%.25]
  99. // CHECK:STDOUT: %.loc13_13.3: <specific function> = specific_function %.loc13_13.2, @Convert.2(constants.%.1) [template = constants.%.26]
  100. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %.loc13_13.3(%.loc13_12) [template = constants.%.27]
  101. // CHECK:STDOUT: %.loc13_13.4: %i32 = value_of_initializer %int.convert_checked [template = constants.%.27]
  102. // CHECK:STDOUT: %.loc13_13.5: %i32 = converted %.loc13_12, %.loc13_13.4 [template = constants.%.27]
  103. // CHECK:STDOUT: return %.loc13_13.5
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: fn @G() -> %i32 {
  107. // CHECK:STDOUT: !entry:
  108. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  109. // CHECK:STDOUT: return <error>
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT: