fail_field_modifiers.carbon 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.
  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.
  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 on `let` declaration outside of an interface.
  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 on `let` declaration outside of an interface.
  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: %.1: type = tuple_type () [template]
  37. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  38. // CHECK:STDOUT: %.2: type = unbound_element_type %Class, i32 [template]
  39. // CHECK:STDOUT: %.3: i32 = int_literal 0 [template]
  40. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  41. // CHECK:STDOUT: %.5: type = struct_type {.j: i32, .k: i32} [template]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  46. // CHECK:STDOUT: .Core = %Core
  47. // CHECK:STDOUT: .Class = %Class.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  50. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  51. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  52. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  53. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  54. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: class @Class {
  58. // CHECK:STDOUT: %int.make_type_32.loc17: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc17_18.1: type = value_of_initializer %int.make_type_32.loc17 [template = i32]
  60. // CHECK:STDOUT: %.loc17_18.2: type = converted %int.make_type_32.loc17, %.loc17_18.1 [template = i32]
  61. // CHECK:STDOUT: %.loc17_16: %.2 = field_decl j, element0 [template]
  62. // CHECK:STDOUT: %int.make_type_32.loc23: init type = call constants.%Int32() [template = i32]
  63. // CHECK:STDOUT: %.loc23_16.1: type = value_of_initializer %int.make_type_32.loc23 [template = i32]
  64. // CHECK:STDOUT: %.loc23_16.2: type = converted %int.make_type_32.loc23, %.loc23_16.1 [template = i32]
  65. // CHECK:STDOUT: %.loc23_14: %.2 = field_decl k, element1 [template]
  66. // CHECK:STDOUT: %int.make_type_32.loc29: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc29_18.1: type = value_of_initializer %int.make_type_32.loc29 [template = i32]
  68. // CHECK:STDOUT: %.loc29_18.2: type = converted %int.make_type_32.loc29, %.loc29_18.1 [template = i32]
  69. // CHECK:STDOUT: %.loc29_24: i32 = int_literal 0 [template = constants.%.3]
  70. // CHECK:STDOUT: %l: i32 = bind_name l, %.loc29_24
  71. // CHECK:STDOUT: %int.make_type_32.loc34: init type = call constants.%Int32() [template = i32]
  72. // CHECK:STDOUT: %.loc34_16.1: type = value_of_initializer %int.make_type_32.loc34 [template = i32]
  73. // CHECK:STDOUT: %.loc34_16.2: type = converted %int.make_type_32.loc34, %.loc34_16.1 [template = i32]
  74. // CHECK:STDOUT: %.loc34_22: i32 = int_literal 1 [template = constants.%.4]
  75. // CHECK:STDOUT: %m: i32 = bind_name m, %.loc34_22
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: !members:
  78. // CHECK:STDOUT: .Self = constants.%Class
  79. // CHECK:STDOUT: .j = %.loc17_16
  80. // CHECK:STDOUT: .k = %.loc23_14
  81. // CHECK:STDOUT: .l = %l
  82. // CHECK:STDOUT: .m = %m
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  86. // CHECK:STDOUT: