fail_scope.carbon 4.8 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/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: %Int32.type: type = fn_type @Int32 [template]
  26. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  27. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  28. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  29. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  30. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  31. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  32. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  33. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  34. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: imports {
  38. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  39. // CHECK:STDOUT: .Int32 = %import_ref
  40. // CHECK:STDOUT: import Core//prelude
  41. // CHECK:STDOUT: import Core//prelude/operators
  42. // CHECK:STDOUT: import Core//prelude/types
  43. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  44. // CHECK:STDOUT: import Core//prelude/operators/as
  45. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  46. // CHECK:STDOUT: import Core//prelude/operators/comparison
  47. // CHECK:STDOUT: import Core//prelude/types/bool
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+15, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: file {
  53. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  54. // CHECK:STDOUT: .Core = imports.%Core
  55. // CHECK:STDOUT: .Class = %Class.decl
  56. // CHECK:STDOUT: .G = %G.decl
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Core.import = import Core
  59. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  60. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  61. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  62. // CHECK:STDOUT: %return.param_patt: i32 = param_pattern %return.patt, runtime_param0
  63. // CHECK:STDOUT: } {
  64. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %.loc17_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  66. // CHECK:STDOUT: %.loc17_11.2: type = converted %int.make_type_32, %.loc17_11.1 [template = i32]
  67. // CHECK:STDOUT: %return.param: i32 = param runtime_param0
  68. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: class @Class {
  73. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  74. // CHECK:STDOUT: %return.patt: i32 = return_slot_pattern
  75. // CHECK:STDOUT: %return.param_patt: i32 = param_pattern %return.patt, runtime_param0
  76. // CHECK:STDOUT: } {
  77. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  78. // CHECK:STDOUT: %.loc12_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  79. // CHECK:STDOUT: %.loc12_13.2: type = converted %int.make_type_32, %.loc12_13.1 [template = i32]
  80. // CHECK:STDOUT: %return.param: i32 = param runtime_param0
  81. // CHECK:STDOUT: %return: ref i32 = return_slot %return.param
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %.loc15: <witness> = complete_type_witness %.2 [template = constants.%.3]
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: !members:
  86. // CHECK:STDOUT: .Self = constants.%Class
  87. // CHECK:STDOUT: .F = %F.decl
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @F() -> i32 {
  93. // CHECK:STDOUT: !entry:
  94. // CHECK:STDOUT: %.loc13: i32 = int_literal 1 [template = constants.%.4]
  95. // CHECK:STDOUT: return %.loc13
  96. // CHECK:STDOUT: }
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @G() -> i32 {
  99. // CHECK:STDOUT: !entry:
  100. // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
  101. // CHECK:STDOUT: return <error>
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: