fail_unbound_field.carbon 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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_unbound_field.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_unbound_field.carbon
  10. class Class {
  11. var field: i32;
  12. fn F() -> i32 {
  13. // CHECK:STDERR: fail_unbound_field.carbon:[[@LINE+4]]:12: ERROR: Expression cannot be used as a value.
  14. // CHECK:STDERR: return field;
  15. // CHECK:STDERR: ^~~~~
  16. // CHECK:STDERR:
  17. return field;
  18. }
  19. }
  20. fn G() -> i32 {
  21. // CHECK:STDERR: fail_unbound_field.carbon:[[@LINE+3]]:10: ERROR: Expression cannot be used as a value.
  22. // CHECK:STDERR: return Class.field;
  23. // CHECK:STDERR: ^~~~~~~~~~~
  24. return Class.field;
  25. }
  26. // CHECK:STDOUT: --- fail_unbound_field.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  30. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  31. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  32. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  33. // CHECK:STDOUT: %.2: type = unbound_element_type %Class, i32 [template]
  34. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  35. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  36. // CHECK:STDOUT: %.3: type = struct_type {.field: i32} [template]
  37. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  38. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  43. // CHECK:STDOUT: .Core = %Core
  44. // CHECK:STDOUT: .Class = %Class.decl
  45. // CHECK:STDOUT: .G = %G.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  48. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {}
  49. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  51. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  52. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  53. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  54. // CHECK:STDOUT: %.loc22_11.1: type = value_of_initializer %int.make_type_32 [template = i32]
  55. // CHECK:STDOUT: %.loc22_11.2: type = converted %int.make_type_32, %.loc22_11.1 [template = i32]
  56. // CHECK:STDOUT: @G.%return: ref i32 = var <return slot>
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: class @Class {
  61. // CHECK:STDOUT: %int.make_type_32.loc12: init type = call constants.%Int32() [template = i32]
  62. // CHECK:STDOUT: %.loc12_14.1: type = value_of_initializer %int.make_type_32.loc12 [template = i32]
  63. // CHECK:STDOUT: %.loc12_14.2: type = converted %int.make_type_32.loc12, %.loc12_14.1 [template = i32]
  64. // CHECK:STDOUT: %.loc12_12: %.2 = field_decl field, element0 [template]
  65. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  66. // CHECK:STDOUT: %int.make_type_32.loc13: init type = call constants.%Int32() [template = i32]
  67. // CHECK:STDOUT: %.loc13_13.1: type = value_of_initializer %int.make_type_32.loc13 [template = i32]
  68. // CHECK:STDOUT: %.loc13_13.2: type = converted %int.make_type_32.loc13, %.loc13_13.1 [template = i32]
  69. // CHECK:STDOUT: %return.var: ref i32 = var <return slot>
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT:
  72. // CHECK:STDOUT: !members:
  73. // CHECK:STDOUT: .Self = constants.%Class
  74. // CHECK:STDOUT: .field = %.loc12_12
  75. // CHECK:STDOUT: .F = %F.decl
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @F() -> i32 {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %field.ref: %.2 = name_ref field, @Class.%.loc12_12 [template = @Class.%.loc12_12]
  83. // CHECK:STDOUT: return <error>
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @G() -> i32 {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  89. // CHECK:STDOUT: %field.ref: %.2 = name_ref field, @Class.%.loc12_12 [template = @Class.%.loc12_12]
  90. // CHECK:STDOUT: return <error>
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT: