fail_field_modifiers.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_field_modifiers.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_field_modifiers.carbon
  10. class Class {
  11. // CHECK:STDERR: fail_field_modifiers.carbon:[[@LINE+4]]:3: error: `default` not allowed on `var` declaration [ModifierNotAllowedOnDeclaration]
  12. // CHECK:STDERR: default var j: i32;
  13. // CHECK:STDERR: ^~~~~~~
  14. // CHECK:STDERR:
  15. default var j: i32;
  16. // CHECK:STDERR: fail_field_modifiers.carbon:[[@LINE+4]]:3: error: `final` not allowed on `var` declaration [ModifierNotAllowedOnDeclaration]
  17. // CHECK:STDERR: final var k: i32;
  18. // CHECK:STDERR: ^~~~~
  19. // CHECK:STDERR:
  20. final var k: i32;
  21. // CHECK:STDERR: fail_field_modifiers.carbon:[[@LINE+4]]:3: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
  22. // CHECK:STDERR: default let l: i32 = 0;
  23. // CHECK:STDERR: ^~~~~~~
  24. // CHECK:STDERR:
  25. default let l: i32 = 0;
  26. // CHECK:STDERR: fail_field_modifiers.carbon:[[@LINE+3]]:3: error: `final` not allowed; requires interface scope [ModifierRequiresInterface]
  27. // CHECK:STDERR: final let m: i32 = 1;
  28. // CHECK:STDERR: ^~~~~
  29. final let m: i32 = 1;
  30. }
  31. // CHECK:STDOUT: --- fail_field_modifiers.carbon
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: constants {
  34. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  35. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  36. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  37. // CHECK:STDOUT: %.1: type = unbound_element_type %Class, i32 [template]
  38. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 0 [template]
  39. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert.1, @ImplicitAs(i32) [template]
  40. // CHECK:STDOUT: %Convert.type.15: type = fn_type @Convert.11 [template]
  41. // CHECK:STDOUT: %Convert.15: %Convert.type.15 = struct_value () [template]
  42. // CHECK:STDOUT: %.26: <witness> = interface_witness (%Convert.15) [template]
  43. // CHECK:STDOUT: %.27: <bound method> = bound_method %.2, %Convert.15 [template]
  44. // CHECK:STDOUT: %.28: i32 = int_value 0 [template]
  45. // CHECK:STDOUT: %.29: Core.IntLiteral = int_value 1 [template]
  46. // CHECK:STDOUT: %.30: <bound method> = bound_method %.29, %Convert.15 [template]
  47. // CHECK:STDOUT: %.31: i32 = int_value 1 [template]
  48. // CHECK:STDOUT: %.32: type = struct_type {.j: i32, .k: i32} [template]
  49. // CHECK:STDOUT: %.33: <witness> = complete_type_witness %.32 [template]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: imports {
  53. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  54. // CHECK:STDOUT: .Int32 = %import_ref.1
  55. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  56. // CHECK:STDOUT: import Core//prelude
  57. // CHECK:STDOUT: import Core//prelude/...
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: file {
  62. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  63. // CHECK:STDOUT: .Core = imports.%Core
  64. // CHECK:STDOUT: .Class = %Class.decl
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %Core.import = import Core
  67. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: class @Class {
  71. // CHECK:STDOUT: %int.make_type_32.loc17: init type = call constants.%Int32() [template = i32]
  72. // CHECK:STDOUT: %.loc17_18.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
  73. // CHECK:STDOUT: %.loc17_18.2: type = converted %int.make_type_32.loc17, %.loc17_18.1 [template = i32]
  74. // CHECK:STDOUT: %.loc17_16: %.1 = field_decl j, element0 [template]
  75. // CHECK:STDOUT: %int.make_type_32.loc23: init type = call constants.%Int32() [template = i32]
  76. // CHECK:STDOUT: %.loc23_16.1: type = value_of_initializer %int.make_type_32.loc23 [template = i32]
  77. // CHECK:STDOUT: %.loc23_16.2: type = converted %int.make_type_32.loc23, %.loc23_16.1 [template = i32]
  78. // CHECK:STDOUT: %.loc23_14: %.1 = field_decl k, element1 [template]
  79. // CHECK:STDOUT: %int.make_type_32.loc29: init type = call constants.%Int32() [template = i32]
  80. // CHECK:STDOUT: %.loc29_18.1: type = value_of_initializer %int.make_type_32.loc29 [template = i32]
  81. // CHECK:STDOUT: %.loc29_18.2: type = converted %int.make_type_32.loc29, %.loc29_18.1 [template = i32]
  82. // CHECK:STDOUT: %.loc29_24: Core.IntLiteral = int_value 0 [template = constants.%.2]
  83. // CHECK:STDOUT: %.loc29_25.1: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.15]
  84. // CHECK:STDOUT: %.loc29_25.2: <bound method> = bound_method %.loc29_24, %.loc29_25.1 [template = constants.%.27]
  85. // CHECK:STDOUT: %int.convert_checked.loc29: init i32 = call %.loc29_25.2(%.loc29_24) [template = constants.%.28]
  86. // CHECK:STDOUT: %.loc29_25.3: i32 = value_of_initializer %int.convert_checked.loc29 [template = constants.%.28]
  87. // CHECK:STDOUT: %.loc29_25.4: i32 = converted %.loc29_24, %.loc29_25.3 [template = constants.%.28]
  88. // CHECK:STDOUT: %l: i32 = bind_name l, %.loc29_25.4
  89. // CHECK:STDOUT: %int.make_type_32.loc34: init type = call constants.%Int32() [template = i32]
  90. // CHECK:STDOUT: %.loc34_16.1: type = value_of_initializer %int.make_type_32.loc34 [template = i32]
  91. // CHECK:STDOUT: %.loc34_16.2: type = converted %int.make_type_32.loc34, %.loc34_16.1 [template = i32]
  92. // CHECK:STDOUT: %.loc34_22: Core.IntLiteral = int_value 1 [template = constants.%.29]
  93. // CHECK:STDOUT: %.loc34_23.1: %Convert.type.2 = interface_witness_access constants.%.26, element0 [template = constants.%Convert.15]
  94. // CHECK:STDOUT: %.loc34_23.2: <bound method> = bound_method %.loc34_22, %.loc34_23.1 [template = constants.%.30]
  95. // CHECK:STDOUT: %int.convert_checked.loc34: init i32 = call %.loc34_23.2(%.loc34_22) [template = constants.%.31]
  96. // CHECK:STDOUT: %.loc34_23.3: i32 = value_of_initializer %int.convert_checked.loc34 [template = constants.%.31]
  97. // CHECK:STDOUT: %.loc34_23.4: i32 = converted %.loc34_22, %.loc34_23.3 [template = constants.%.31]
  98. // CHECK:STDOUT: %m: i32 = bind_name m, %.loc34_23.4
  99. // CHECK:STDOUT: %.loc35: <witness> = complete_type_witness %.32 [template = constants.%.33]
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: !members:
  102. // CHECK:STDOUT: .Self = constants.%Class
  103. // CHECK:STDOUT: .j = %.loc17_16
  104. // CHECK:STDOUT: .k = %.loc23_14
  105. // CHECK:STDOUT: .l = %l
  106. // CHECK:STDOUT: .m = %m
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: