fail_self_param.carbon 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 [template]
  21. // CHECK:STDOUT: %C.generic: %C.type = struct_value () [template]
  22. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  23. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
  24. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  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 [template] {
  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 [template = 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: %x.param_patt: <error> = value_param_pattern %x.patt.loc15_22.1, runtime_param<invalid> [symbolic = %x.patt.loc15_22.2 (constants.%x.patt)]
  44. // CHECK:STDOUT: } {
  45. // CHECK:STDOUT: %x.param: <error> = value_param runtime_param<invalid>
  46. // CHECK:STDOUT: %self.ref: <error> = name_ref self, <error> [template = <error>]
  47. // CHECK:STDOUT: %x: <error> = bind_symbolic_name x, 0, %x.param [template = <error>]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: name_binding_decl {
  50. // CHECK:STDOUT: %v.patt: <error> = binding_pattern v
  51. // CHECK:STDOUT: %.loc16: <error> = var_pattern %v.patt
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %v.var: ref <error> = var v
  54. // CHECK:STDOUT: %.1: <error> = splice_block <error> [template = <error>] {
  55. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, %C.decl [template = constants.%C.generic]
  56. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %v: <error> = bind_name v, <error>
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: generic class @C(%x: <error>) {
  62. // CHECK:STDOUT: %x.patt.loc15_22.2: <error> = symbolic_binding_pattern x, 0 [symbolic = %x.patt.loc15_22.2 (constants.%x.patt)]
  63. // CHECK:STDOUT:
  64. // CHECK:STDOUT: !definition:
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: class {
  67. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
  68. // CHECK:STDOUT: complete_type_witness = %complete_type
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: !members:
  71. // CHECK:STDOUT: .Self = <error>
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: specific @C(<error>) {
  76. // CHECK:STDOUT: %x.patt.loc15_22.2 => <error>
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: