fail_local_decl.carbon 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/function/definition/no_prelude/fail_local_decl.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/definition/no_prelude/fail_local_decl.carbon
  10. // --- fail_virtual.carbon
  11. library "[[@TEST_NAME]]";
  12. fn F() {
  13. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  14. // CHECK:STDERR: default fn F();
  15. // CHECK:STDERR: ^~~~~~~
  16. // CHECK:STDERR:
  17. default fn F();
  18. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `impl` not allowed; requires class scope [ModifierRequiresClass]
  19. // CHECK:STDERR: impl fn G();
  20. // CHECK:STDERR: ^~~~
  21. // CHECK:STDERR:
  22. impl fn G();
  23. // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `virtual` not allowed; requires class scope [ModifierRequiresClass]
  24. // CHECK:STDERR: virtual fn H();
  25. // CHECK:STDERR: ^~~~~~~
  26. // CHECK:STDERR:
  27. virtual fn H();
  28. }
  29. // --- fail_access.carbon
  30. library "[[@TEST_NAME]]";
  31. fn F() {
  32. // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `private` not allowed; requires class or file scope [ModifierPrivateNotAllowed]
  33. // CHECK:STDERR: private var v: {};
  34. // CHECK:STDERR: ^~~~~~~
  35. // CHECK:STDERR:
  36. private var v: {};
  37. // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
  38. // CHECK:STDERR: protected var w: {};
  39. // CHECK:STDERR: ^~~~~~~~~
  40. // CHECK:STDERR:
  41. protected var w: {};
  42. }
  43. // CHECK:STDOUT: --- fail_virtual.carbon
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: constants {
  46. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.1 [template]
  47. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [template]
  48. // CHECK:STDOUT: %F.type.21a: type = fn_type @F.2 [template]
  49. // CHECK:STDOUT: %F.c14: %F.type.21a = struct_value () [template]
  50. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  51. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  52. // CHECK:STDOUT: %H.type: type = fn_type @H [template]
  53. // CHECK:STDOUT: %H: %H.type = struct_value () [template]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  58. // CHECK:STDOUT: .F = %F.decl
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.1 [template = constants.%F.c41] {} {}
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @F.1() {
  64. // CHECK:STDOUT: !entry:
  65. // CHECK:STDOUT: %F.decl: %F.type.21a = fn_decl @F.2 [template = constants.%F.c14] {} {}
  66. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
  67. // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
  68. // CHECK:STDOUT: return
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: fn @F.2();
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @G();
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @H();
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: --- fail_access.carbon
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: constants {
  80. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  81. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  82. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: file {
  86. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  87. // CHECK:STDOUT: .F = %F.decl
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @F() {
  93. // CHECK:STDOUT: !entry:
  94. // CHECK:STDOUT: name_binding_decl {
  95. // CHECK:STDOUT: %v.patt: %empty_struct_type = binding_pattern v
  96. // CHECK:STDOUT: %.loc9_11: %empty_struct_type = var_pattern %v.patt
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %v.var: ref %empty_struct_type = var v
  99. // CHECK:STDOUT: %.loc9_19.1: type = splice_block %.loc9_19.3 [template = constants.%empty_struct_type] {
  100. // CHECK:STDOUT: %.loc9_19.2: %empty_struct_type = struct_literal ()
  101. // CHECK:STDOUT: %.loc9_19.3: type = converted %.loc9_19.2, constants.%empty_struct_type [template = constants.%empty_struct_type]
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %v: ref %empty_struct_type = bind_name v, %v.var
  104. // CHECK:STDOUT: name_binding_decl {
  105. // CHECK:STDOUT: %w.patt: %empty_struct_type = binding_pattern w
  106. // CHECK:STDOUT: %.loc14_13: %empty_struct_type = var_pattern %w.patt
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %w.var: ref %empty_struct_type = var w
  109. // CHECK:STDOUT: %.loc14_21.1: type = splice_block %.loc14_21.3 [template = constants.%empty_struct_type] {
  110. // CHECK:STDOUT: %.loc14_21.2: %empty_struct_type = struct_literal ()
  111. // CHECK:STDOUT: %.loc14_21.3: type = converted %.loc14_21.2, constants.%empty_struct_type [template = constants.%empty_struct_type]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %w: ref %empty_struct_type = bind_name w, %w.var
  114. // CHECK:STDOUT: return
  115. // CHECK:STDOUT: }
  116. // CHECK:STDOUT: