fail_explicit_self_param.carbon 3.3 KB

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