fail_init_as_inplace.carbon 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. class Class {
  7. var a: i32;
  8. var b: i32;
  9. }
  10. fn G(p: Class*);
  11. fn F() {
  12. // TODO: This case should presumably work: `{...} as Class` should be an
  13. // initializing expression, not a value expression.
  14. //
  15. // CHECK:STDERR: fail_init_as_inplace.carbon:[[@LINE+3]]:18: ERROR: Cannot copy value of type `Class`.
  16. // CHECK:STDERR: var c: Class = {.a = 1, .b = 2} as Class;
  17. // CHECK:STDERR: ^~~~~~~~~~~~~~~~
  18. var c: Class = {.a = 1, .b = 2} as Class;
  19. G(&c);
  20. }
  21. // CHECK:STDOUT: --- fail_init_as_inplace.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %.loc10_1.1: type = struct_type {.a: i32, .b: i32}
  25. // CHECK:STDOUT: %.loc10_1.2: type = ptr_type {.a: i32, .b: i32}
  26. // CHECK:STDOUT: %.loc22: type = tuple_type ()
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: file {
  30. // CHECK:STDOUT: package: <namespace> = namespace {.Class = %Class.decl, .G = %G, .F = %F}
  31. // CHECK:STDOUT: %Class.decl = class_decl @Class, ()
  32. // CHECK:STDOUT: %Class: type = class_type @Class
  33. // CHECK:STDOUT: %G: <function> = fn_decl @G
  34. // CHECK:STDOUT: %F: <function> = fn_decl @F
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: class @Class {
  38. // CHECK:STDOUT: %.loc8_8.1: type = unbound_element_type Class, i32
  39. // CHECK:STDOUT: %.loc8_8.2: <unbound element of class Class> = field_decl a, element0
  40. // CHECK:STDOUT: %a: <unbound element of class Class> = bind_name a, %.loc8_8.2
  41. // CHECK:STDOUT: %.loc9_8.1: type = unbound_element_type Class, i32
  42. // CHECK:STDOUT: %.loc9_8.2: <unbound element of class Class> = field_decl b, element1
  43. // CHECK:STDOUT: %b: <unbound element of class Class> = bind_name b, %.loc9_8.2
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: !members:
  46. // CHECK:STDOUT: .a = %a
  47. // CHECK:STDOUT: .b = %b
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: fn @G(%p: Class*);
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: fn @F() {
  53. // CHECK:STDOUT: !entry:
  54. // CHECK:STDOUT: %Class.ref.loc21_10: type = name_ref Class, file.%Class
  55. // CHECK:STDOUT: %c.var: ref Class = var c
  56. // CHECK:STDOUT: %c: ref Class = bind_name c, %c.var
  57. // CHECK:STDOUT: %.loc21_24: i32 = int_literal 1
  58. // CHECK:STDOUT: %.loc21_32: i32 = int_literal 2
  59. // CHECK:STDOUT: %.loc21_33.1: {.a: i32, .b: i32} = struct_literal (%.loc21_24, %.loc21_32)
  60. // CHECK:STDOUT: %Class.ref.loc21_38: type = name_ref Class, file.%Class
  61. // CHECK:STDOUT: %.loc21_33.2: ref Class = temporary_storage
  62. // CHECK:STDOUT: %.loc21_33.3: ref i32 = class_element_access %.loc21_33.2, element0
  63. // CHECK:STDOUT: %.loc21_33.4: init i32 = initialize_from %.loc21_24 to %.loc21_33.3
  64. // CHECK:STDOUT: %.loc21_33.5: ref i32 = class_element_access %.loc21_33.2, element1
  65. // CHECK:STDOUT: %.loc21_33.6: init i32 = initialize_from %.loc21_32 to %.loc21_33.5
  66. // CHECK:STDOUT: %.loc21_33.7: init Class = class_init (%.loc21_33.4, %.loc21_33.6), %.loc21_33.2
  67. // CHECK:STDOUT: %.loc21_33.8: ref Class = temporary %.loc21_33.2, %.loc21_33.7
  68. // CHECK:STDOUT: %.loc21_33.9: ref Class = converted %.loc21_33.1, %.loc21_33.8
  69. // CHECK:STDOUT: %.loc21_33.10: Class = bind_value %.loc21_33.9
  70. // CHECK:STDOUT: assign %c.var, <error>
  71. // CHECK:STDOUT: %G.ref: <function> = name_ref G, file.%G
  72. // CHECK:STDOUT: %c.ref: ref Class = name_ref c, %c
  73. // CHECK:STDOUT: %.loc22_5: Class* = address_of %c.ref
  74. // CHECK:STDOUT: %.loc22_4: init () = call %G.ref(%.loc22_5)
  75. // CHECK:STDOUT: return
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: