fail_self_param.carbon 5.8 KB

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