fail_self_param.carbon 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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_self_param.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_self_param.carbon
  10. // CHECK:STDERR: fail_self_param.carbon:[[@LINE+4]]:9: error: `self` parameter only allowed on functions [SelfParameterNotAllowed]
  11. // CHECK:STDERR: class C[self:! type](x:! self) {}
  12. // CHECK:STDERR: ^~~~~~~~~~~
  13. // CHECK:STDERR:
  14. class C[self:! type](x:! self) {}
  15. var v: C(0);
  16. // CHECK:STDOUT: --- fail_self_param.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %x.patt: <error> = symbolic_binding_pattern x, 0 [symbolic]
  20. // CHECK:STDOUT: %C.type: type = generic_class_type @C [concrete]
  21. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [concrete]
  22. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  23. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete]
  24. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  29. // CHECK:STDOUT: import Core//prelude
  30. // CHECK:STDOUT: import Core//prelude/...
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: file {
  35. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  36. // CHECK:STDOUT: .Core = imports.%Core
  37. // CHECK:STDOUT: .C = %C.decl
  38. // CHECK:STDOUT: .v = %v
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core.import = import Core
  41. // CHECK:STDOUT: %C.decl: %C.type = class_decl @C [concrete = constants.%C.generic] {
  42. // CHECK:STDOUT: %x.patt.loc15_22.1: <error> = symbolic_binding_pattern x, 0 [symbolic = %x.patt.loc15_22.2 (constants.%x.patt)]
  43. // CHECK:STDOUT: } {
  44. // CHECK:STDOUT: %self.ref: <error> = name_ref self, <error> [concrete = <error>]
  45. // CHECK:STDOUT: %x: <error> = bind_symbolic_name x, 0 [concrete = <error>]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: name_binding_decl {
  48. // CHECK:STDOUT: %v.patt: <error> = binding_pattern v
  49. // CHECK:STDOUT: %.loc16: <error> = var_pattern %v.patt
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %v.var: ref <error> = var v
  52. // CHECK:STDOUT: %.1: <error> = splice_block <error> [concrete = <error>] {
  53. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, %C.decl [concrete = constants.%C.generic]
  54. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %v: <error> = bind_name v, <error>
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT:
  59. // CHECK:STDOUT: generic class @C(%x: <error>) {
  60. // CHECK:STDOUT: %x.patt.loc15_22.2: <error> = symbolic_binding_pattern x, 0 [symbolic = %x.patt.loc15_22.2 (constants.%x.patt)]
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !definition:
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: class {
  65. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [concrete = constants.%complete_type]
  66. // CHECK:STDOUT: complete_type_witness = %complete_type
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: !members:
  69. // CHECK:STDOUT: .Self = <error>
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: specific @C(<error>) {
  74. // CHECK:STDOUT: %x.patt.loc15_22.2 => <error>
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: