fail_error_recovery.carbon 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/operators/overloaded/fail_error_recovery.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/overloaded/fail_error_recovery.carbon
  10. // Each of these should only produce one error, and shouldn't complain that
  11. // `<error>` doesn't implement an operator.
  12. fn F() {
  13. // CHECK:STDERR: fail_error_recovery.carbon:[[@LINE+4]]:3: error: name `undeclared` not found [NameNotFound]
  14. // CHECK:STDERR: undeclared + 1;
  15. // CHECK:STDERR: ^~~~~~~~~~
  16. // CHECK:STDERR:
  17. undeclared + 1;
  18. }
  19. fn G(n: i32) {
  20. // CHECK:STDERR: fail_error_recovery.carbon:[[@LINE+4]]:7: error: name `undeclared` not found [NameNotFound]
  21. // CHECK:STDERR: n + undeclared;
  22. // CHECK:STDERR: ^~~~~~~~~~
  23. // CHECK:STDERR:
  24. n + undeclared;
  25. }
  26. // CHECK:STDOUT: --- fail_error_recovery.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  30. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  31. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  32. // CHECK:STDOUT: %Add.type: type = facet_type <@Add> [template]
  33. // CHECK:STDOUT: %Op.type.545: type = fn_type @Op.1 [template]
  34. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  35. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  36. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  37. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  38. // CHECK:STDOUT: %impl_witness.01d: <witness> = impl_witness (imports.%Core.import_ref.344), @impl.14(%int_32) [template]
  39. // CHECK:STDOUT: %Op.type.210: type = fn_type @Op.2, @impl.14(%int_32) [template]
  40. // CHECK:STDOUT: %Op.c82: %Op.type.210 = struct_value () [template]
  41. // CHECK:STDOUT: %Add.facet: %Add.type = facet_value %i32, %impl_witness.01d [template]
  42. // CHECK:STDOUT: %.ede: type = fn_type_with_self_type %Op.type.545, %Add.facet [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: imports {
  46. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  47. // CHECK:STDOUT: .Add = %Core.Add
  48. // CHECK:STDOUT: .Int = %Core.Int
  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: .F = %F.decl
  58. // CHECK:STDOUT: .G = %G.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %Core.import = import Core
  61. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  62. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  63. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  64. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, runtime_param0
  65. // CHECK:STDOUT: } {
  66. // CHECK:STDOUT: %n.param: %i32 = value_param runtime_param0
  67. // CHECK:STDOUT: %.loc22: type = splice_block %i32 [template = constants.%i32] {
  68. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  69. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @F() {
  76. // CHECK:STDOUT: !entry:
  77. // CHECK:STDOUT: %undeclared.ref: <error> = name_ref undeclared, <error> [template = <error>]
  78. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  79. // CHECK:STDOUT: %impl.elem0: <error> = impl_witness_access <error>, element0 [template = <error>]
  80. // CHECK:STDOUT: return
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @G(%n.param_patt: %i32) {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: %n.ref: %i32 = name_ref n, %n
  86. // CHECK:STDOUT: %undeclared.ref: <error> = name_ref undeclared, <error> [template = <error>]
  87. // CHECK:STDOUT: %impl.elem0: %.ede = impl_witness_access constants.%impl_witness.01d, element0 [template = constants.%Op.c82]
  88. // CHECK:STDOUT: %bound_method: <bound method> = bound_method %n.ref, %impl.elem0
  89. // CHECK:STDOUT: return
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: