fail_derived_to_base.carbon 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. base class A1 {
  7. var a: i32;
  8. }
  9. base class A2 {
  10. var a: i32;
  11. }
  12. class B2 {
  13. extend base: A2;
  14. var b: i32;
  15. }
  16. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+4]]:38: ERROR: Cannot implicitly convert from `B2*` to `A1*`.
  17. // CHECK:STDERR: fn ConvertUnrelated(p: B2*) -> A1* { return p; }
  18. // CHECK:STDERR: ^~~~~~~~~
  19. // CHECK:STDERR:
  20. fn ConvertUnrelated(p: B2*) -> A1* { return p; }
  21. class Incomplete;
  22. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+3]]:47: ERROR: Cannot implicitly convert from `Incomplete*` to `A2*`.
  23. // CHECK:STDERR: fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }
  24. // CHECK:STDERR: ^~~~~~~~~
  25. fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }
  26. // CHECK:STDOUT: --- fail_derived_to_base.carbon
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: constants {
  29. // CHECK:STDOUT: %A1: type = class_type @A1 [template]
  30. // CHECK:STDOUT: %.1: type = unbound_element_type A1, i32 [template]
  31. // CHECK:STDOUT: %.2: type = struct_type {.a: i32} [template]
  32. // CHECK:STDOUT: %A2: type = class_type @A2 [template]
  33. // CHECK:STDOUT: %.3: type = unbound_element_type A2, i32 [template]
  34. // CHECK:STDOUT: %B2: type = class_type @B2 [template]
  35. // CHECK:STDOUT: %.4: type = ptr_type {.a: i32} [template]
  36. // CHECK:STDOUT: %.5: type = unbound_element_type B2, A2 [template]
  37. // CHECK:STDOUT: %.6: type = unbound_element_type B2, i32 [template]
  38. // CHECK:STDOUT: %.7: type = struct_type {.base: A2, .b: i32} [template]
  39. // CHECK:STDOUT: %.8: type = ptr_type B2 [template]
  40. // CHECK:STDOUT: %.9: type = ptr_type A1 [template]
  41. // CHECK:STDOUT: %.10: type = struct_type {.base: {.a: i32}*, .b: i32} [template]
  42. // CHECK:STDOUT: %.11: type = ptr_type {.base: {.a: i32}*, .b: i32} [template]
  43. // CHECK:STDOUT: %.12: type = ptr_type {.base: A2, .b: i32} [template]
  44. // CHECK:STDOUT: %Incomplete: type = class_type @Incomplete [template]
  45. // CHECK:STDOUT: %.13: type = ptr_type Incomplete [template]
  46. // CHECK:STDOUT: %.14: type = ptr_type A2 [template]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: file {
  50. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  51. // CHECK:STDOUT: .Core = %Core
  52. // CHECK:STDOUT: .A1 = %A1.decl
  53. // CHECK:STDOUT: .A2 = %A2.decl
  54. // CHECK:STDOUT: .B2 = %B2.decl
  55. // CHECK:STDOUT: .ConvertUnrelated = %ConvertUnrelated
  56. // CHECK:STDOUT: .Incomplete = %Incomplete.decl
  57. // CHECK:STDOUT: .ConvertIncomplete = %ConvertIncomplete
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  60. // CHECK:STDOUT: %A1.decl: type = class_decl @A1 [template = constants.%A1] {}
  61. // CHECK:STDOUT: %A2.decl: type = class_decl @A2 [template = constants.%A2] {}
  62. // CHECK:STDOUT: %B2.decl: type = class_decl @B2 [template = constants.%B2] {}
  63. // CHECK:STDOUT: %ConvertUnrelated: <function> = fn_decl @ConvertUnrelated [template] {
  64. // CHECK:STDOUT: %B2.ref: type = name_ref B2, %B2.decl [template = constants.%B2]
  65. // CHECK:STDOUT: %.loc24_26: type = ptr_type B2 [template = constants.%.8]
  66. // CHECK:STDOUT: %p.loc24_21.1: B2* = param p
  67. // CHECK:STDOUT: @ConvertUnrelated.%p: B2* = bind_name p, %p.loc24_21.1
  68. // CHECK:STDOUT: %A1.ref: type = name_ref A1, %A1.decl [template = constants.%A1]
  69. // CHECK:STDOUT: %.loc24_34: type = ptr_type A1 [template = constants.%.9]
  70. // CHECK:STDOUT: %return.var.loc24: ref A1* = var <return slot>
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Incomplete.decl: type = class_decl @Incomplete [template = constants.%Incomplete] {}
  73. // CHECK:STDOUT: %ConvertIncomplete: <function> = fn_decl @ConvertIncomplete [template] {
  74. // CHECK:STDOUT: %Incomplete.ref: type = name_ref Incomplete, %Incomplete.decl [template = constants.%Incomplete]
  75. // CHECK:STDOUT: %.loc31_35: type = ptr_type Incomplete [template = constants.%.13]
  76. // CHECK:STDOUT: %p.loc31_22.1: Incomplete* = param p
  77. // CHECK:STDOUT: @ConvertIncomplete.%p: Incomplete* = bind_name p, %p.loc31_22.1
  78. // CHECK:STDOUT: %A2.ref: type = name_ref A2, %A2.decl [template = constants.%A2]
  79. // CHECK:STDOUT: %.loc31_43: type = ptr_type A2 [template = constants.%.14]
  80. // CHECK:STDOUT: %return.var.loc31: ref A2* = var <return slot>
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT:
  84. // CHECK:STDOUT: class @A1 {
  85. // CHECK:STDOUT: %.loc8: <unbound element of class A1> = field_decl a, element0 [template]
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = constants.%A1
  89. // CHECK:STDOUT: .a = %.loc8
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: class @A2 {
  93. // CHECK:STDOUT: %.loc12: <unbound element of class A2> = field_decl a, element0 [template]
  94. // CHECK:STDOUT:
  95. // CHECK:STDOUT: !members:
  96. // CHECK:STDOUT: .Self = constants.%A2
  97. // CHECK:STDOUT: .a = %.loc12
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT:
  100. // CHECK:STDOUT: class @B2 {
  101. // CHECK:STDOUT: %A2.ref: type = name_ref A2, file.%A2.decl [template = constants.%A2]
  102. // CHECK:STDOUT: %.loc16: <unbound element of class B2> = base_decl A2, element0 [template]
  103. // CHECK:STDOUT: %.loc17: <unbound element of class B2> = field_decl b, element1 [template]
  104. // CHECK:STDOUT:
  105. // CHECK:STDOUT: !members:
  106. // CHECK:STDOUT: .Self = constants.%B2
  107. // CHECK:STDOUT: .base = %.loc16
  108. // CHECK:STDOUT: .b = %.loc17
  109. // CHECK:STDOUT: extend name_scope3
  110. // CHECK:STDOUT: }
  111. // CHECK:STDOUT:
  112. // CHECK:STDOUT: class @Incomplete;
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: fn @ConvertUnrelated(%p: B2*) -> A1* {
  115. // CHECK:STDOUT: !entry:
  116. // CHECK:STDOUT: %p.ref: B2* = name_ref p, %p
  117. // CHECK:STDOUT: return <error>
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: fn @ConvertIncomplete(%p: Incomplete*) -> A2* {
  121. // CHECK:STDOUT: !entry:
  122. // CHECK:STDOUT: %p.ref: Incomplete* = name_ref p, %p
  123. // CHECK:STDOUT: return <error>
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: