fail_local_decl.carbon 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/destroy.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/definition/fail_local_decl.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/definition/fail_local_decl.carbon
  14. // --- fail_virtual.carbon
  15. library "[[@TEST_NAME]]";
  16. fn F() {
  17. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  18. // CHECK:STDERR: default fn F();
  19. // CHECK:STDERR: ^~~~~~~
  20. // CHECK:STDERR:
  21. default fn F();
  22. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `override` not allowed; requires class scope [ModifierRequiresClass]
  23. // CHECK:STDERR: override fn G();
  24. // CHECK:STDERR: ^~~~~~~~
  25. // CHECK:STDERR:
  26. override fn G();
  27. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `virtual` not allowed; requires class scope [ModifierRequiresClass]
  28. // CHECK:STDERR: virtual fn H();
  29. // CHECK:STDERR: ^~~~~~~
  30. // CHECK:STDERR:
  31. virtual fn H();
  32. }
  33. // --- fail_access.carbon
  34. library "[[@TEST_NAME]]";
  35. fn F() {
  36. // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `private` not allowed; requires class or file scope [ModifierPrivateNotAllowed]
  37. // CHECK:STDERR: private var v: {};
  38. // CHECK:STDERR: ^~~~~~~
  39. // CHECK:STDERR:
  40. private var v: {};
  41. // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  42. // CHECK:STDERR: protected var w: {};
  43. // CHECK:STDERR: ^~~~~~~~~
  44. // CHECK:STDERR:
  45. protected var w: {};
  46. }
  47. // CHECK:STDOUT: --- fail_virtual.carbon
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: constants {
  50. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.loc4 [concrete]
  51. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [concrete]
  52. // CHECK:STDOUT: %F.type.21a: type = fn_type @F.loc9 [concrete]
  53. // CHECK:STDOUT: %F.c14: %F.type.21a = struct_value () [concrete]
  54. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  55. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  56. // CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
  57. // CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: imports {
  61. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  62. // CHECK:STDOUT: import Core//prelude
  63. // CHECK:STDOUT: import Core//prelude/...
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: file {
  68. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  69. // CHECK:STDOUT: .Core = imports.%Core
  70. // CHECK:STDOUT: .F = %F.decl
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.loc4 [concrete = constants.%F.c41] {} {}
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: fn @F.loc4() {
  77. // CHECK:STDOUT: !entry:
  78. // CHECK:STDOUT: %F.decl: %F.type.21a = fn_decl @F.loc9 [concrete = constants.%F.c14] {} {}
  79. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {} {}
  80. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [concrete = constants.%H] {} {}
  81. // CHECK:STDOUT: return
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: fn @F.loc9();
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @G();
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @H();
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: --- fail_access.carbon
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: constants {
  93. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  94. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  95. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  96. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  97. // CHECK:STDOUT: %pattern_type.a96: type = pattern_type %empty_struct_type [concrete]
  98. // CHECK:STDOUT: %Destroy.type: type = facet_type <@Destroy> [concrete]
  99. // CHECK:STDOUT: %type_where: type = facet_type <type where .Self impls <CanAggregateDestroy>> [concrete]
  100. // CHECK:STDOUT: %facet_value: %type_where = facet_value %empty_struct_type, () [concrete]
  101. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.type.6a4: type = fn_type @AggregateT.as_type.as.Destroy.impl.Op, @AggregateT.as_type.as.Destroy.impl(%facet_value) [concrete]
  102. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bf3: %AggregateT.as_type.as.Destroy.impl.Op.type.6a4 = struct_value () [concrete]
  103. // CHECK:STDOUT: %ptr.c28: type = ptr_type %empty_struct_type [concrete]
  104. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn: <specific function> = specific_function %AggregateT.as_type.as.Destroy.impl.Op.bf3, @AggregateT.as_type.as.Destroy.impl.Op(%facet_value) [concrete]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT:
  107. // CHECK:STDOUT: imports {
  108. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  109. // CHECK:STDOUT: .Destroy = %Core.Destroy
  110. // CHECK:STDOUT: import Core//prelude
  111. // CHECK:STDOUT: import Core//prelude/...
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %Core.Destroy: type = import_ref Core//prelude/parts/destroy, Destroy, loaded [concrete = constants.%Destroy.type]
  114. // CHECK:STDOUT: }
  115. // CHECK:STDOUT:
  116. // CHECK:STDOUT: file {
  117. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  118. // CHECK:STDOUT: .Core = imports.%Core
  119. // CHECK:STDOUT: .F = %F.decl
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT: %Core.import = import Core
  122. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT:
  125. // CHECK:STDOUT: fn @F() {
  126. // CHECK:STDOUT: !entry:
  127. // CHECK:STDOUT: name_binding_decl {
  128. // CHECK:STDOUT: %v.patt: %pattern_type.a96 = binding_pattern v [concrete]
  129. // CHECK:STDOUT: %v.var_patt: %pattern_type.a96 = var_pattern %v.patt [concrete]
  130. // CHECK:STDOUT: }
  131. // CHECK:STDOUT: %v.var: ref %empty_struct_type = var %v.var_patt
  132. // CHECK:STDOUT: %.loc9_19.1: type = splice_block %.loc9_19.3 [concrete = constants.%empty_struct_type] {
  133. // CHECK:STDOUT: %.loc9_19.2: %empty_struct_type = struct_literal ()
  134. // CHECK:STDOUT: %.loc9_19.3: type = converted %.loc9_19.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  135. // CHECK:STDOUT: }
  136. // CHECK:STDOUT: %v: ref %empty_struct_type = bind_name v, %v.var
  137. // CHECK:STDOUT: name_binding_decl {
  138. // CHECK:STDOUT: %w.patt: %pattern_type.a96 = binding_pattern w [concrete]
  139. // CHECK:STDOUT: %w.var_patt: %pattern_type.a96 = var_pattern %w.patt [concrete]
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT: %w.var: ref %empty_struct_type = var %w.var_patt
  142. // CHECK:STDOUT: %.loc14_21.1: type = splice_block %.loc14_21.3 [concrete = constants.%empty_struct_type] {
  143. // CHECK:STDOUT: %.loc14_21.2: %empty_struct_type = struct_literal ()
  144. // CHECK:STDOUT: %.loc14_21.3: type = converted %.loc14_21.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  145. // CHECK:STDOUT: }
  146. // CHECK:STDOUT: %w: ref %empty_struct_type = bind_name w, %w.var
  147. // CHECK:STDOUT: %facet_value.loc14: %type_where = facet_value constants.%empty_struct_type, () [concrete = constants.%facet_value]
  148. // CHECK:STDOUT: %.loc14_13: %type_where = converted constants.%empty_struct_type, %facet_value.loc14 [concrete = constants.%facet_value]
  149. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc14: <bound method> = bound_method %w.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.bf3
  150. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.1: <specific function> = specific_function constants.%AggregateT.as_type.as.Destroy.impl.Op.bf3, @AggregateT.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%AggregateT.as_type.as.Destroy.impl.Op.specific_fn]
  151. // CHECK:STDOUT: %bound_method.loc14: <bound method> = bound_method %w.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.1
  152. // CHECK:STDOUT: %addr.loc14: %ptr.c28 = addr_of %w.var
  153. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc14: init %empty_tuple.type = call %bound_method.loc14(%addr.loc14)
  154. // CHECK:STDOUT: %facet_value.loc9: %type_where = facet_value constants.%empty_struct_type, () [concrete = constants.%facet_value]
  155. // CHECK:STDOUT: %.loc9_11: %type_where = converted constants.%empty_struct_type, %facet_value.loc9 [concrete = constants.%facet_value]
  156. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.bound.loc9: <bound method> = bound_method %v.var, constants.%AggregateT.as_type.as.Destroy.impl.Op.bf3
  157. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.2: <specific function> = specific_function constants.%AggregateT.as_type.as.Destroy.impl.Op.bf3, @AggregateT.as_type.as.Destroy.impl.Op(constants.%facet_value) [concrete = constants.%AggregateT.as_type.as.Destroy.impl.Op.specific_fn]
  158. // CHECK:STDOUT: %bound_method.loc9: <bound method> = bound_method %v.var, %AggregateT.as_type.as.Destroy.impl.Op.specific_fn.2
  159. // CHECK:STDOUT: %addr.loc9: %ptr.c28 = addr_of %v.var
  160. // CHECK:STDOUT: %AggregateT.as_type.as.Destroy.impl.Op.call.loc9: init %empty_tuple.type = call %bound_method.loc9(%addr.loc9)
  161. // CHECK:STDOUT: return
  162. // CHECK:STDOUT: }
  163. // CHECK:STDOUT: