fail_modifiers.carbon 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/let/fail_modifiers.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_modifiers.carbon
  10. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  11. // CHECK:STDERR: protected let b: i32 = 1;
  12. // CHECK:STDERR: ^~~~~~~~~
  13. // CHECK:STDERR:
  14. protected let b: i32 = 1;
  15. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  16. // CHECK:STDERR: default let c: i32 = 1;
  17. // CHECK:STDERR: ^~~~~~~
  18. // CHECK:STDERR:
  19. default let c: i32 = 1;
  20. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: error: `final` not allowed; requires interface scope [ModifierRequiresInterface]
  21. // CHECK:STDERR: final let d: i32 = 1;
  22. // CHECK:STDERR: ^~~~~
  23. // CHECK:STDERR:
  24. final let d: i32 = 1;
  25. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: error: `virtual` not allowed on `let` declaration [ModifierNotAllowedOnDeclaration]
  26. // CHECK:STDERR: virtual let e: i32 = 1;
  27. // CHECK:STDERR: ^~~~~~~
  28. // CHECK:STDERR:
  29. virtual let e: i32 = 1;
  30. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+11]]:1: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  31. // CHECK:STDERR: default final let f: i32 = 1;
  32. // CHECK:STDERR: ^~~~~~~
  33. // CHECK:STDERR:
  34. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:9: error: `final` not allowed on declaration with `default` [ModifierNotAllowedWith]
  35. // CHECK:STDERR: default final let f: i32 = 1;
  36. // CHECK:STDERR: ^~~~~
  37. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `default` previously appeared here [ModifierPrevious]
  38. // CHECK:STDERR: default final let f: i32 = 1;
  39. // CHECK:STDERR: ^~~~~~~
  40. // CHECK:STDERR:
  41. default final let f: i32 = 1;
  42. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+11]]:1: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  43. // CHECK:STDERR: default default let g: i32 = 1;
  44. // CHECK:STDERR: ^~~~~~~
  45. // CHECK:STDERR:
  46. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:9: error: `default` repeated on declaration [ModifierRepeated]
  47. // CHECK:STDERR: default default let g: i32 = 1;
  48. // CHECK:STDERR: ^~~~~~~
  49. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `default` previously appeared here [ModifierPrevious]
  50. // CHECK:STDERR: default default let g: i32 = 1;
  51. // CHECK:STDERR: ^~~~~~~
  52. // CHECK:STDERR:
  53. default default let g: i32 = 1;
  54. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+11]]:1: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  55. // CHECK:STDERR: protected private let h: i32 = 1;
  56. // CHECK:STDERR: ^~~~~~~~~
  57. // CHECK:STDERR:
  58. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+7]]:11: error: `private` not allowed on declaration with `protected` [ModifierNotAllowedWith]
  59. // CHECK:STDERR: protected private let h: i32 = 1;
  60. // CHECK:STDERR: ^~~~~~~
  61. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+4]]:1: note: `protected` previously appeared here [ModifierPrevious]
  62. // CHECK:STDERR: protected private let h: i32 = 1;
  63. // CHECK:STDERR: ^~~~~~~~~
  64. // CHECK:STDERR:
  65. protected private let h: i32 = 1;
  66. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+10]]:1: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  67. // CHECK:STDERR: protected protected let i: i32 = 1;
  68. // CHECK:STDERR: ^~~~~~~~~
  69. // CHECK:STDERR:
  70. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+6]]:11: error: `protected` repeated on declaration [ModifierRepeated]
  71. // CHECK:STDERR: protected protected let i: i32 = 1;
  72. // CHECK:STDERR: ^~~~~~~~~
  73. // CHECK:STDERR: fail_modifiers.carbon:[[@LINE+3]]:1: note: `protected` previously appeared here [ModifierPrevious]
  74. // CHECK:STDERR: protected protected let i: i32 = 1;
  75. // CHECK:STDERR: ^~~~~~~~~
  76. protected protected let i: i32 = 1;
  77. // CHECK:STDOUT: --- fail_modifiers.carbon
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: constants {
  80. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  81. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  82. // CHECK:STDOUT: %int_1.5b8: Core.IntLiteral = int_value 1 [template]
  83. // CHECK:STDOUT: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  84. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  85. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  86. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  87. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_1.5b8, %Convert.925 [template]
  88. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(%int_32) [template]
  89. // CHECK:STDOUT: %int_1.c60: %i32 = int_value 1 [template]
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: imports {
  93. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  94. // CHECK:STDOUT: .Int = %import_ref.187
  95. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  96. // CHECK:STDOUT: import Core//prelude
  97. // CHECK:STDOUT: import Core//prelude/...
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: file {
  102. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  103. // CHECK:STDOUT: .Core = imports.%Core
  104. // CHECK:STDOUT: .b = @__global_init.%b
  105. // CHECK:STDOUT: .c = @__global_init.%c
  106. // CHECK:STDOUT: .d = @__global_init.%d
  107. // CHECK:STDOUT: .e = @__global_init.%e
  108. // CHECK:STDOUT: .f = @__global_init.%f
  109. // CHECK:STDOUT: .g = @__global_init.%g
  110. // CHECK:STDOUT: .h = @__global_init.%h
  111. // CHECK:STDOUT: .i = @__global_init.%i
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %Core.import = import Core
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: fn @__global_init() {
  117. // CHECK:STDOUT: !entry:
  118. // CHECK:STDOUT: %int_1.loc15: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  119. // CHECK:STDOUT: %impl.elem0.loc15: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  120. // CHECK:STDOUT: %Convert.bound.loc15: <bound method> = bound_method %int_1.loc15, %impl.elem0.loc15 [template = constants.%Convert.bound]
  121. // CHECK:STDOUT: %Convert.specific_fn.loc15: <specific function> = specific_function %Convert.bound.loc15, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  122. // CHECK:STDOUT: %int.convert_checked.loc15: init %i32 = call %Convert.specific_fn.loc15(%int_1.loc15) [template = constants.%int_1.c60]
  123. // CHECK:STDOUT: %.loc15_25.1: %i32 = value_of_initializer %int.convert_checked.loc15 [template = constants.%int_1.c60]
  124. // CHECK:STDOUT: %.loc15_25.2: %i32 = converted %int_1.loc15, %.loc15_25.1 [template = constants.%int_1.c60]
  125. // CHECK:STDOUT: %b: %i32 = bind_name b, %.loc15_25.2
  126. // CHECK:STDOUT: %int_1.loc21: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  127. // CHECK:STDOUT: %impl.elem0.loc21: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  128. // CHECK:STDOUT: %Convert.bound.loc21: <bound method> = bound_method %int_1.loc21, %impl.elem0.loc21 [template = constants.%Convert.bound]
  129. // CHECK:STDOUT: %Convert.specific_fn.loc21: <specific function> = specific_function %Convert.bound.loc21, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  130. // CHECK:STDOUT: %int.convert_checked.loc21: init %i32 = call %Convert.specific_fn.loc21(%int_1.loc21) [template = constants.%int_1.c60]
  131. // CHECK:STDOUT: %.loc21_23.1: %i32 = value_of_initializer %int.convert_checked.loc21 [template = constants.%int_1.c60]
  132. // CHECK:STDOUT: %.loc21_23.2: %i32 = converted %int_1.loc21, %.loc21_23.1 [template = constants.%int_1.c60]
  133. // CHECK:STDOUT: %c: %i32 = bind_name c, %.loc21_23.2
  134. // CHECK:STDOUT: %int_1.loc27: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  135. // CHECK:STDOUT: %impl.elem0.loc27: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  136. // CHECK:STDOUT: %Convert.bound.loc27: <bound method> = bound_method %int_1.loc27, %impl.elem0.loc27 [template = constants.%Convert.bound]
  137. // CHECK:STDOUT: %Convert.specific_fn.loc27: <specific function> = specific_function %Convert.bound.loc27, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  138. // CHECK:STDOUT: %int.convert_checked.loc27: init %i32 = call %Convert.specific_fn.loc27(%int_1.loc27) [template = constants.%int_1.c60]
  139. // CHECK:STDOUT: %.loc27_21.1: %i32 = value_of_initializer %int.convert_checked.loc27 [template = constants.%int_1.c60]
  140. // CHECK:STDOUT: %.loc27_21.2: %i32 = converted %int_1.loc27, %.loc27_21.1 [template = constants.%int_1.c60]
  141. // CHECK:STDOUT: %d: %i32 = bind_name d, %.loc27_21.2
  142. // CHECK:STDOUT: %int_1.loc33: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  143. // CHECK:STDOUT: %impl.elem0.loc33: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  144. // CHECK:STDOUT: %Convert.bound.loc33: <bound method> = bound_method %int_1.loc33, %impl.elem0.loc33 [template = constants.%Convert.bound]
  145. // CHECK:STDOUT: %Convert.specific_fn.loc33: <specific function> = specific_function %Convert.bound.loc33, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  146. // CHECK:STDOUT: %int.convert_checked.loc33: init %i32 = call %Convert.specific_fn.loc33(%int_1.loc33) [template = constants.%int_1.c60]
  147. // CHECK:STDOUT: %.loc33_23.1: %i32 = value_of_initializer %int.convert_checked.loc33 [template = constants.%int_1.c60]
  148. // CHECK:STDOUT: %.loc33_23.2: %i32 = converted %int_1.loc33, %.loc33_23.1 [template = constants.%int_1.c60]
  149. // CHECK:STDOUT: %e: %i32 = bind_name e, %.loc33_23.2
  150. // CHECK:STDOUT: %int_1.loc46: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  151. // CHECK:STDOUT: %impl.elem0.loc46: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  152. // CHECK:STDOUT: %Convert.bound.loc46: <bound method> = bound_method %int_1.loc46, %impl.elem0.loc46 [template = constants.%Convert.bound]
  153. // CHECK:STDOUT: %Convert.specific_fn.loc46: <specific function> = specific_function %Convert.bound.loc46, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  154. // CHECK:STDOUT: %int.convert_checked.loc46: init %i32 = call %Convert.specific_fn.loc46(%int_1.loc46) [template = constants.%int_1.c60]
  155. // CHECK:STDOUT: %.loc46_29.1: %i32 = value_of_initializer %int.convert_checked.loc46 [template = constants.%int_1.c60]
  156. // CHECK:STDOUT: %.loc46_29.2: %i32 = converted %int_1.loc46, %.loc46_29.1 [template = constants.%int_1.c60]
  157. // CHECK:STDOUT: %f: %i32 = bind_name f, %.loc46_29.2
  158. // CHECK:STDOUT: %int_1.loc59: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  159. // CHECK:STDOUT: %impl.elem0.loc59: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  160. // CHECK:STDOUT: %Convert.bound.loc59: <bound method> = bound_method %int_1.loc59, %impl.elem0.loc59 [template = constants.%Convert.bound]
  161. // CHECK:STDOUT: %Convert.specific_fn.loc59: <specific function> = specific_function %Convert.bound.loc59, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  162. // CHECK:STDOUT: %int.convert_checked.loc59: init %i32 = call %Convert.specific_fn.loc59(%int_1.loc59) [template = constants.%int_1.c60]
  163. // CHECK:STDOUT: %.loc59_31.1: %i32 = value_of_initializer %int.convert_checked.loc59 [template = constants.%int_1.c60]
  164. // CHECK:STDOUT: %.loc59_31.2: %i32 = converted %int_1.loc59, %.loc59_31.1 [template = constants.%int_1.c60]
  165. // CHECK:STDOUT: %g: %i32 = bind_name g, %.loc59_31.2
  166. // CHECK:STDOUT: %int_1.loc72: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  167. // CHECK:STDOUT: %impl.elem0.loc72: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  168. // CHECK:STDOUT: %Convert.bound.loc72: <bound method> = bound_method %int_1.loc72, %impl.elem0.loc72 [template = constants.%Convert.bound]
  169. // CHECK:STDOUT: %Convert.specific_fn.loc72: <specific function> = specific_function %Convert.bound.loc72, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  170. // CHECK:STDOUT: %int.convert_checked.loc72: init %i32 = call %Convert.specific_fn.loc72(%int_1.loc72) [template = constants.%int_1.c60]
  171. // CHECK:STDOUT: %.loc72_33.1: %i32 = value_of_initializer %int.convert_checked.loc72 [template = constants.%int_1.c60]
  172. // CHECK:STDOUT: %.loc72_33.2: %i32 = converted %int_1.loc72, %.loc72_33.1 [template = constants.%int_1.c60]
  173. // CHECK:STDOUT: %h: %i32 = bind_name h, %.loc72_33.2
  174. // CHECK:STDOUT: %int_1.loc84: Core.IntLiteral = int_value 1 [template = constants.%int_1.5b8]
  175. // CHECK:STDOUT: %impl.elem0.loc84: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  176. // CHECK:STDOUT: %Convert.bound.loc84: <bound method> = bound_method %int_1.loc84, %impl.elem0.loc84 [template = constants.%Convert.bound]
  177. // CHECK:STDOUT: %Convert.specific_fn.loc84: <specific function> = specific_function %Convert.bound.loc84, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn]
  178. // CHECK:STDOUT: %int.convert_checked.loc84: init %i32 = call %Convert.specific_fn.loc84(%int_1.loc84) [template = constants.%int_1.c60]
  179. // CHECK:STDOUT: %.loc84_35.1: %i32 = value_of_initializer %int.convert_checked.loc84 [template = constants.%int_1.c60]
  180. // CHECK:STDOUT: %.loc84_35.2: %i32 = converted %int_1.loc84, %.loc84_35.1 [template = constants.%int_1.c60]
  181. // CHECK:STDOUT: %i: %i32 = bind_name i, %.loc84_35.2
  182. // CHECK:STDOUT: return
  183. // CHECK:STDOUT: }
  184. // CHECK:STDOUT: