fail_abstract.carbon 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. abstract class Abstract {
  7. var a: i32;
  8. }
  9. class Derived {
  10. extend base: Abstract;
  11. var d: i32;
  12. }
  13. fn Make() -> Derived {
  14. // TODO: This should be valid, and should construct an instance of `partial Abstract` as the base.
  15. // CHECK:STDERR: fail_abstract.carbon:[[@LINE+3]]:19: ERROR: Cannot construct instance of abstract class. Consider using `partial Abstract` instead.
  16. // CHECK:STDERR: return {.base = {.a = 1}, .d = 7};
  17. // CHECK:STDERR: ^~~~~~~~
  18. return {.base = {.a = 1}, .d = 7};
  19. }
  20. fn Access(d: Derived) -> (i32, i32) {
  21. return (d.d, d.base.a);
  22. }
  23. // CHECK:STDOUT: --- fail_abstract.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %Abstract: type = class_type @Abstract [template]
  27. // CHECK:STDOUT: %.1: type = unbound_element_type Abstract, i32 [template]
  28. // CHECK:STDOUT: %.2: type = struct_type {.a: i32} [template]
  29. // CHECK:STDOUT: %Derived: type = class_type @Derived [template]
  30. // CHECK:STDOUT: %.3: type = ptr_type {.a: i32} [template]
  31. // CHECK:STDOUT: %.4: type = unbound_element_type Derived, Abstract [template]
  32. // CHECK:STDOUT: %.5: type = unbound_element_type Derived, i32 [template]
  33. // CHECK:STDOUT: %.6: type = struct_type {.base: Abstract, .d: i32} [template]
  34. // CHECK:STDOUT: %.7: type = struct_type {.base: {.a: i32}*, .d: i32} [template]
  35. // CHECK:STDOUT: %.8: type = ptr_type {.base: {.a: i32}*, .d: i32} [template]
  36. // CHECK:STDOUT: %.9: type = ptr_type {.base: Abstract, .d: i32} [template]
  37. // CHECK:STDOUT: %.10: i32 = int_literal 1 [template]
  38. // CHECK:STDOUT: %.11: i32 = int_literal 7 [template]
  39. // CHECK:STDOUT: %.12: type = struct_type {.base: {.a: i32}, .d: i32} [template]
  40. // CHECK:STDOUT: %.13: type = tuple_type (type, type) [template]
  41. // CHECK:STDOUT: %.14: type = tuple_type (i32, i32) [template]
  42. // CHECK:STDOUT: %.15: type = ptr_type (i32, i32) [template]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Abstract = %Abstract.decl
  48. // CHECK:STDOUT: .Derived = %Derived.decl
  49. // CHECK:STDOUT: .Make = %Make
  50. // CHECK:STDOUT: .Access = %Access
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Abstract.decl: type = class_decl @Abstract [template = constants.%Abstract] {}
  53. // CHECK:STDOUT: %Derived.decl: type = class_decl @Derived [template = constants.%Derived] {}
  54. // CHECK:STDOUT: %Make: <function> = fn_decl @Make [template] {
  55. // CHECK:STDOUT: %Derived.ref.loc17: type = name_ref Derived, %Derived.decl [template = constants.%Derived]
  56. // CHECK:STDOUT: @Make.%return: ref Derived = var <return slot>
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %Access: <function> = fn_decl @Access [template] {
  59. // CHECK:STDOUT: %Derived.ref.loc25: type = name_ref Derived, %Derived.decl [template = constants.%Derived]
  60. // CHECK:STDOUT: %d.loc25_11.1: Derived = param d
  61. // CHECK:STDOUT: @Access.%d: Derived = bind_name d, %d.loc25_11.1
  62. // CHECK:STDOUT: %.loc25_35.1: (type, type) = tuple_literal (i32, i32)
  63. // CHECK:STDOUT: %.loc25_35.2: type = converted %.loc25_35.1, constants.%.14 [template = constants.%.14]
  64. // CHECK:STDOUT: @Access.%return: ref (i32, i32) = var <return slot>
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: class @Abstract {
  69. // CHECK:STDOUT: %.loc8: <unbound element of class Abstract> = field_decl a, element0 [template]
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: !members:
  72. // CHECK:STDOUT: .Self = constants.%Abstract
  73. // CHECK:STDOUT: .a = %.loc8
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: class @Derived {
  77. // CHECK:STDOUT: %Abstract.ref: type = name_ref Abstract, file.%Abstract.decl [template = constants.%Abstract]
  78. // CHECK:STDOUT: %.loc12: <unbound element of class Derived> = base_decl Abstract, element0 [template]
  79. // CHECK:STDOUT: %.loc14: <unbound element of class Derived> = field_decl d, element1 [template]
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: !members:
  82. // CHECK:STDOUT: .Self = constants.%Derived
  83. // CHECK:STDOUT: .base = %.loc12
  84. // CHECK:STDOUT: .d = %.loc14
  85. // CHECK:STDOUT: extend name_scope1
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @Make() -> %return: Derived {
  89. // CHECK:STDOUT: !entry:
  90. // CHECK:STDOUT: %.loc22_25: i32 = int_literal 1 [template = constants.%.10]
  91. // CHECK:STDOUT: %.loc22_26: {.a: i32} = struct_literal (%.loc22_25)
  92. // CHECK:STDOUT: %.loc22_34: i32 = int_literal 7 [template = constants.%.11]
  93. // CHECK:STDOUT: %.loc22_35: {.base: {.a: i32}, .d: i32} = struct_literal (%.loc22_26, %.loc22_34)
  94. // CHECK:STDOUT: return <error>
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @Access(%d: Derived) -> %return: (i32, i32) {
  98. // CHECK:STDOUT: !entry:
  99. // CHECK:STDOUT: %d.ref.loc26_11: Derived = name_ref d, %d
  100. // CHECK:STDOUT: %d.ref.loc26_12: <unbound element of class Derived> = name_ref d, @Derived.%.loc14 [template = @Derived.%.loc14]
  101. // CHECK:STDOUT: %.loc26_12.1: ref i32 = class_element_access %d.ref.loc26_11, element1
  102. // CHECK:STDOUT: %.loc26_12.2: i32 = bind_value %.loc26_12.1
  103. // CHECK:STDOUT: %d.ref.loc26_16: Derived = name_ref d, %d
  104. // CHECK:STDOUT: %base.ref: <unbound element of class Derived> = name_ref base, @Derived.%.loc12 [template = @Derived.%.loc12]
  105. // CHECK:STDOUT: %.loc26_17.1: ref Abstract = class_element_access %d.ref.loc26_16, element0
  106. // CHECK:STDOUT: %.loc26_17.2: Abstract = bind_value %.loc26_17.1
  107. // CHECK:STDOUT: %a.ref: <unbound element of class Abstract> = name_ref a, @Abstract.%.loc8 [template = @Abstract.%.loc8]
  108. // CHECK:STDOUT: %.loc26_22.1: ref i32 = class_element_access %.loc26_17.2, element0
  109. // CHECK:STDOUT: %.loc26_22.2: i32 = bind_value %.loc26_22.1
  110. // CHECK:STDOUT: %.loc26_24.1: (i32, i32) = tuple_literal (%.loc26_12.2, %.loc26_22.2)
  111. // CHECK:STDOUT: %.loc26_24.2: ref i32 = tuple_access %return, element0
  112. // CHECK:STDOUT: %.loc26_24.3: init i32 = initialize_from %.loc26_12.2 to %.loc26_24.2
  113. // CHECK:STDOUT: %.loc26_24.4: ref i32 = tuple_access %return, element1
  114. // CHECK:STDOUT: %.loc26_24.5: init i32 = initialize_from %.loc26_22.2 to %.loc26_24.4
  115. // CHECK:STDOUT: %.loc26_24.6: init (i32, i32) = tuple_init (%.loc26_24.3, %.loc26_24.5) to %return
  116. // CHECK:STDOUT: %.loc26_24.7: init (i32, i32) = converted %.loc26_24.1, %.loc26_24.6
  117. // CHECK:STDOUT: return %.loc26_24.7
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT: