fail_self_param.carbon 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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+3]]:9: error: `self` parameter only allowed on functions [SelfParameterNotAllowed]
  11. // CHECK:STDERR: class C[self:! type](x:! self) {}
  12. // CHECK:STDERR: ^~~~~~~~~~~
  13. class C[self:! type](x:! self) {}
  14. var v: C(0);
  15. // CHECK:STDOUT: --- fail_self_param.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %x.patt: <error> = symbolic_binding_pattern x, 0 [symbolic]
  19. // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
  20. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [template]
  21. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  22. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  23. // CHECK:STDOUT: }
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: imports {
  26. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  27. // CHECK:STDOUT: import Core//prelude
  28. // CHECK:STDOUT: import Core//prelude/...
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: file {
  33. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  34. // CHECK:STDOUT: .Core = imports.%Core
  35. // CHECK:STDOUT: .C = %C.decl
  36. // CHECK:STDOUT: .v = %v
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %Core.import = import Core
  39. // CHECK:STDOUT: %C.decl: %C.type = class_decl @C [template = constants.%C.generic] {
  40. // CHECK:STDOUT: %x.patt.loc14_22.1: <error> = symbolic_binding_pattern x, 0 [symbolic = %x.patt.loc14_22.2 (constants.%x.patt)]
  41. // CHECK:STDOUT: %x.param_patt: <error> = value_param_pattern %x.patt.loc14_22.1, runtime_param<invalid> [symbolic = %x.patt.loc14_22.2 (constants.%x.patt)]
  42. // CHECK:STDOUT: } {
  43. // CHECK:STDOUT: %x.param: <error> = value_param runtime_param<invalid>
  44. // CHECK:STDOUT: %self.ref: <error> = name_ref self, <error> [template = <error>]
  45. // CHECK:STDOUT: %x: <error> = bind_symbolic_name x, 0, %x.param [template = <error>]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %v.var: ref <error> = var v
  48. // CHECK:STDOUT: %v: ref <error> = bind_name v, %v.var
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: generic class @C(%x: <error>) {
  52. // CHECK:STDOUT: %x.patt.loc14_22.2: <error> = symbolic_binding_pattern x, 0 [symbolic = %x.patt.loc14_22.2 (constants.%x.patt)]
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: !definition:
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: class {
  57. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  58. // CHECK:STDOUT: complete_type_witness = %complete_type
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: !members:
  61. // CHECK:STDOUT: .Self = <error>
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: specific @C(<error>) {
  66. // CHECK:STDOUT: %x.patt.loc14_22.2 => <error>
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: