fail_unknown_member.carbon 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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_unknown_member.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_unknown_member.carbon
  10. class Class {
  11. var n: i32;
  12. }
  13. fn G(c: Class) -> i32 {
  14. // TODO: Mention the scope in which we looked for the name.
  15. // CHECK:STDERR: fail_unknown_member.carbon:[[@LINE+3]]:10: error: name `something` not found
  16. // CHECK:STDERR: return c.something;
  17. // CHECK:STDERR: ^~~~~~~~~~~
  18. return c.something;
  19. }
  20. // CHECK:STDOUT: --- fail_unknown_member.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  24. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  25. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  26. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  27. // CHECK:STDOUT: %.2: type = unbound_element_type %Class, i32 [template]
  28. // CHECK:STDOUT: %.3: type = struct_type {.n: i32} [template]
  29. // CHECK:STDOUT: %.4: <witness> = complete_type_witness %.3 [template]
  30. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  31. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  32. // CHECK:STDOUT: %.5: type = ptr_type %.3 [template]
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: imports {
  36. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  37. // CHECK:STDOUT: .Int32 = %import_ref
  38. // CHECK:STDOUT: import Core//prelude
  39. // CHECK:STDOUT: import Core//prelude/operators
  40. // CHECK:STDOUT: import Core//prelude/types
  41. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  42. // CHECK:STDOUT: import Core//prelude/operators/as
  43. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  44. // CHECK:STDOUT: import Core//prelude/operators/comparison
  45. // CHECK:STDOUT: import Core//prelude/types/bool
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: file {
  51. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  52. // CHECK:STDOUT: .Core = imports.%Core
  53. // CHECK:STDOUT: .Class = %Class.decl
  54. // CHECK:STDOUT: .G = %G.decl
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %Core.import = import Core
  57. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  58. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  59. // CHECK:STDOUT: %c.patt: %Class = binding_pattern c
  60. // CHECK:STDOUT: } {
  61. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  62. // CHECK:STDOUT: %c.param: %Class = param c, runtime_param0
  63. // CHECK:STDOUT: %c: %Class = bind_name c, %c.param
  64. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %.loc15_19.1: type = value_of_initializer %int.make_type_32 [template = i32]
  66. // CHECK:STDOUT: %.loc15_19.2: type = converted %int.make_type_32, %.loc15_19.1 [template = i32]
  67. // CHECK:STDOUT: %return: ref i32 = var <return slot>
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: class @Class {
  72. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  73. // CHECK:STDOUT: %.loc12_10.1: type = value_of_initializer %int.make_type_32 [template = i32]
  74. // CHECK:STDOUT: %.loc12_10.2: type = converted %int.make_type_32, %.loc12_10.1 [template = i32]
  75. // CHECK:STDOUT: %.loc12_8: %.2 = field_decl n, element0 [template]
  76. // CHECK:STDOUT: %.loc13: <witness> = complete_type_witness %.3 [template = constants.%.4]
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: !members:
  79. // CHECK:STDOUT: .Self = constants.%Class
  80. // CHECK:STDOUT: .n = %.loc12_8
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @G(%c: %Class) -> i32 {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: %c.ref: %Class = name_ref c, %c
  88. // CHECK:STDOUT: %something.ref: <error> = name_ref something, <error> [template = <error>]
  89. // CHECK:STDOUT: return <error>
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: