fail_self_param.carbon 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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
  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: %self: type = bind_symbolic_name self, 0 [symbolic]
  19. // CHECK:STDOUT: %x: %self = bind_symbolic_name x, 1 [symbolic]
  20. // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
  23. // CHECK:STDOUT: %C.2: type = class_type @C, @C(%self, %x) [symbolic]
  24. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  25. // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.2 [template]
  26. // CHECK:STDOUT: %.4: i32 = int_literal 0 [template]
  27. // CHECK:STDOUT: %C.3: type = class_type @C, @C(i32, %.4) [template]
  28. // CHECK:STDOUT: %.5: type = ptr_type %.2 [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: imports {
  32. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/operators
  35. // CHECK:STDOUT: import Core//prelude/types
  36. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  37. // CHECK:STDOUT: import Core//prelude/operators/as
  38. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  39. // CHECK:STDOUT: import Core//prelude/operators/comparison
  40. // CHECK:STDOUT: import Core//prelude/types/bool
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  46. // CHECK:STDOUT: .Core = imports.%Core
  47. // CHECK:STDOUT: .C = %C.decl
  48. // CHECK:STDOUT: .v = %v
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %C.decl: %C.type = class_decl @C [template = constants.%C.1] {
  52. // CHECK:STDOUT: %self.patt: type = symbolic_binding_pattern self, 0
  53. // CHECK:STDOUT: %x.patt: @C.%self.loc14_9.2 (%self) = symbolic_binding_pattern x, 1
  54. // CHECK:STDOUT: } {
  55. // CHECK:STDOUT: %self.param: type = param self, runtime_param<invalid>
  56. // CHECK:STDOUT: %self.loc14_9.1: type = bind_symbolic_name self, 0, %self.param [symbolic = %self.loc14_9.2 (constants.%self)]
  57. // CHECK:STDOUT: %self.ref: type = name_ref self, %self.loc14_9.1 [symbolic = %self.loc14_9.2 (constants.%self)]
  58. // CHECK:STDOUT: %x.param: @C.%self.loc14_9.2 (%self) = param x, runtime_param<invalid>
  59. // CHECK:STDOUT: %x.loc14_22.1: @C.%self.loc14_9.2 (%self) = bind_symbolic_name x, 1, %x.param [symbolic = %x.loc14_22.2 (constants.%x)]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %C.ref: %C.type = name_ref C, %C.decl [template = constants.%C.1]
  62. // CHECK:STDOUT: %.loc15: i32 = int_literal 0 [template = constants.%.4]
  63. // CHECK:STDOUT: %C: type = class_type @C, @C(i32, constants.%.4) [template = constants.%C.3]
  64. // CHECK:STDOUT: %v.var: ref %C.3 = var v
  65. // CHECK:STDOUT: %v: ref %C.3 = bind_name v, %v.var
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: generic class @C(%self.loc14_9.1: type, %x.loc14_22.1: @C.%self.loc14_9.2 (%self)) {
  69. // CHECK:STDOUT: %self.loc14_9.2: type = bind_symbolic_name self, 0 [symbolic = %self.loc14_9.2 (constants.%self)]
  70. // CHECK:STDOUT: %x.loc14_22.2: %self = bind_symbolic_name x, 1 [symbolic = %x.loc14_22.2 (constants.%x)]
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !definition:
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: class {
  75. // CHECK:STDOUT: %.loc14: <witness> = complete_type_witness %.2 [template = constants.%.3]
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%C.2
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: specific @C(constants.%self, constants.%x) {
  83. // CHECK:STDOUT: %self.loc14_9.2 => constants.%self
  84. // CHECK:STDOUT: %x.loc14_22.2 => constants.%x
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: specific @C(i32, constants.%.4) {
  88. // CHECK:STDOUT: %self.loc14_9.2 => i32
  89. // CHECK:STDOUT: %x.loc14_22.2 => constants.%.4
  90. // CHECK:STDOUT:
  91. // CHECK:STDOUT: !definition:
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: