fail_explicit_self_param.carbon 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/none.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/call/fail_explicit_self_param.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/call/fail_explicit_self_param.carbon
  14. // CHECK:STDERR: fail_explicit_self_param.carbon:[[@LINE+4]]:6: error: `self` can only be declared in an implicit parameter list [SelfOutsideImplicitParamList]
  15. // CHECK:STDERR: fn F(self: ());
  16. // CHECK:STDERR: ^~~~~~~~
  17. // CHECK:STDERR:
  18. fn F(self: ());
  19. fn Run() {
  20. F(());
  21. }
  22. // CHECK:STDOUT: --- fail_explicit_self_param.carbon
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: constants {
  25. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  26. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  27. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_tuple.type [concrete]
  28. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  29. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  30. // CHECK:STDOUT: %Run.type: type = fn_type @Run [concrete]
  31. // CHECK:STDOUT: %Run: %Run.type = struct_value () [concrete]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: file {
  35. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  36. // CHECK:STDOUT: .F = %F.decl
  37. // CHECK:STDOUT: .Run = %Run.decl
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  40. // CHECK:STDOUT: %self.param_patt: %pattern_type = value_param_pattern [concrete]
  41. // CHECK:STDOUT: %self.patt: %pattern_type = at_binding_pattern self, %self.param_patt [concrete]
  42. // CHECK:STDOUT: } {
  43. // CHECK:STDOUT: %self.param: %empty_tuple.type = value_param call_param0
  44. // CHECK:STDOUT: %.loc19_13.1: type = splice_block %.loc19_13.3 [concrete = constants.%empty_tuple.type] {
  45. // CHECK:STDOUT: %.loc19_13.2: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  46. // CHECK:STDOUT: %.loc19_13.3: type = converted %.loc19_13.2, constants.%empty_tuple.type [concrete = constants.%empty_tuple.type]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %self: %empty_tuple.type = value_binding self, %self.param
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [concrete = constants.%Run] {} {}
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: fn @F(%self.param: %empty_tuple.type);
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @Run() {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  58. // CHECK:STDOUT: %.loc22_6.1: %empty_tuple.type = tuple_literal () [concrete = constants.%empty_tuple]
  59. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  60. // CHECK:STDOUT: %.loc22_6.2: %empty_tuple.type = converted %.loc22_6.1, %empty_tuple [concrete = constants.%empty_tuple]
  61. // CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref(%.loc22_6.2)
  62. // CHECK:STDOUT: return
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: