// Part of the Carbon Language project, under the Apache License v2.0 with LLVM // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // // AUTOUPDATE // TIP: To test this file alone, run: // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/generic/complete_in_conversion.carbon // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/complete_in_conversion.carbon // --- fail_derived_to_base.carbon fn Int(N: Core.IntLiteral()) -> type = "int.make_type_signed"; base class B {} class A(N:! i32) { extend base: B; // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+3]]:10: error: integer type width of 0 is not positive [IntWidthNotPositive] // CHECK:STDERR: var n: Int(N); // CHECK:STDERR: ^~~~~~ var n: Int(N); } fn F(a: A(0)*) { // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+4]]:15: note: in `A(0)` used here [ResolvingSpecificHere] // CHECK:STDERR: let b: B* = a; // CHECK:STDERR: ^ // CHECK:STDERR: let b: B* = a; } // CHECK:STDOUT: --- fail_derived_to_base.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %IntLiteral.type: type = fn_type @IntLiteral [template] // CHECK:STDOUT: %IntLiteral: %IntLiteral.type = struct_value () [template] // CHECK:STDOUT: %Int.type.913: type = fn_type @Int.1 [template] // CHECK:STDOUT: %Int.779: %Int.type.913 = struct_value () [template] // CHECK:STDOUT: %B: type = class_type @B [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type.357: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template] // CHECK:STDOUT: %i32: type = class_type @Int.2, @Int.2(%int_32) [template] // CHECK:STDOUT: %N.51e: %i32 = bind_symbolic_name N, 0 [symbolic] // CHECK:STDOUT: %N.patt.8e2: %i32 = symbolic_binding_pattern N, 0 [symbolic] // CHECK:STDOUT: %A.type: type = generic_class_type @A [template] // CHECK:STDOUT: %A.generic: %A.type = struct_value () [template] // CHECK:STDOUT: %A.dd3: type = class_type @A, @A(%N.51e) [symbolic] // CHECK:STDOUT: %A.elem.500: type = unbound_element_type %A.dd3, %B [symbolic] // CHECK:STDOUT: %Convert.type.4ad: type = fn_type @Convert.3, @impl.2(%int_32) [template] // CHECK:STDOUT: %Convert.960: %Convert.type.4ad = struct_value () [template] // CHECK:STDOUT: %Convert.bound.588: = bound_method %N.51e, %Convert.960 [symbolic] // CHECK:STDOUT: %Convert.specific_fn.18b: = specific_function %Convert.bound.588, @Convert.3(%int_32) [symbolic] // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %Convert.specific_fn.18b(%N.51e) [symbolic] // CHECK:STDOUT: %iN.builtin.c5d: type = int_type signed, %int.convert_checked [symbolic] // CHECK:STDOUT: %require_complete.be5: = require_complete_type %iN.builtin.c5d [symbolic] // CHECK:STDOUT: %A.elem.d60: type = unbound_element_type %A.dd3, %iN.builtin.c5d [symbolic] // CHECK:STDOUT: %struct_type.base.n: type = struct_type {.base: %B, .n: %iN.builtin.c5d} [symbolic] // CHECK:STDOUT: %complete_type.547: = complete_type_witness %struct_type.base.n [symbolic] // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template] // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [template] // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [template] // CHECK:STDOUT: %impl_witness.d39: = impl_witness (imports.%Core.import_ref.a5b), @impl.1(%int_32) [template] // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.1(%int_32) [template] // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [template] // CHECK:STDOUT: %ImplicitAs.facet.f7f: %ImplicitAs.type.205 = facet_value Core.IntLiteral, %impl_witness.d39 [template] // CHECK:STDOUT: %.a0b: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet.f7f [template] // CHECK:STDOUT: %Convert.bound.d04: = bound_method %int_0.5c6, %Convert.956 [template] // CHECK:STDOUT: %Convert.specific_fn.d62: = specific_function %Convert.bound.d04, @Convert.2(%int_32) [template] // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [template] // CHECK:STDOUT: %A.6fc: type = class_type @A, @A(%int_0.6a9) [template] // CHECK:STDOUT: %ptr.b65: type = ptr_type %A.6fc [template] // CHECK:STDOUT: %F.type: type = fn_type @F [template] // CHECK:STDOUT: %F: %F.type = struct_value () [template] // CHECK:STDOUT: %ptr.e79: type = ptr_type %B [template] // CHECK:STDOUT: %A.elem.d81: type = unbound_element_type %A.6fc, %B [template] // CHECK:STDOUT: %Convert.bound.0fd: = bound_method %int_0.6a9, %Convert.960 [template] // CHECK:STDOUT: %Convert.specific_fn.f3f: = specific_function %Convert.bound.0fd, @Convert.3(%int_32) [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: .IntLiteral = %Core.IntLiteral // CHECK:STDOUT: .Int = %Core.Int // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Core.IntLiteral: %IntLiteral.type = import_ref Core//prelude/types/int_literal, IntLiteral, loaded [template = constants.%IntLiteral] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .Int = %Int.decl // CHECK:STDOUT: .B = %B.decl // CHECK:STDOUT: .A = %A.decl // CHECK:STDOUT: .F = %F.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Int.decl: %Int.type.913 = fn_decl @Int.1 [template = constants.%Int.779] { // CHECK:STDOUT: %N.patt: Core.IntLiteral = binding_pattern N // CHECK:STDOUT: %N.param_patt: Core.IntLiteral = value_param_pattern %N.patt, runtime_param0 // CHECK:STDOUT: %return.patt: type = return_slot_pattern // CHECK:STDOUT: %return.param_patt: type = out_param_pattern %return.patt, runtime_param1 // CHECK:STDOUT: } { // CHECK:STDOUT: %N.param: Core.IntLiteral = value_param runtime_param0 // CHECK:STDOUT: %.loc2_27.1: type = splice_block %.loc2_27.3 [template = Core.IntLiteral] { // CHECK:STDOUT: %Core.ref: = name_ref Core, imports.%Core [template = imports.%Core] // CHECK:STDOUT: %IntLiteral.ref: %IntLiteral.type = name_ref IntLiteral, imports.%Core.IntLiteral [template = constants.%IntLiteral] // CHECK:STDOUT: %int_literal.make_type: init type = call %IntLiteral.ref() [template = Core.IntLiteral] // CHECK:STDOUT: %.loc2_27.2: type = value_of_initializer %int_literal.make_type [template = Core.IntLiteral] // CHECK:STDOUT: %.loc2_27.3: type = converted %int_literal.make_type, %.loc2_27.2 [template = Core.IntLiteral] // CHECK:STDOUT: } // CHECK:STDOUT: %N: Core.IntLiteral = bind_name N, %N.param // CHECK:STDOUT: %return.param: ref type = out_param runtime_param1 // CHECK:STDOUT: %return: ref type = return_slot %return.param // CHECK:STDOUT: } // CHECK:STDOUT: %B.decl: type = class_decl @B [template = constants.%B] {} {} // CHECK:STDOUT: %A.decl: %A.type = class_decl @A [template = constants.%A.generic] { // CHECK:STDOUT: %N.patt.loc6_9.1: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc6_9.2 (constants.%N.patt.8e2)] // CHECK:STDOUT: %N.param_patt: %i32 = value_param_pattern %N.patt.loc6_9.1, runtime_param [symbolic = %N.patt.loc6_9.2 (constants.%N.patt.8e2)] // CHECK:STDOUT: } { // CHECK:STDOUT: %N.param: %i32 = value_param runtime_param // CHECK:STDOUT: %.loc6: type = splice_block %i32 [template = constants.%i32] { // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32] // CHECK:STDOUT: %i32: type = class_type @Int.2, @Int.2(constants.%int_32) [template = constants.%i32] // CHECK:STDOUT: } // CHECK:STDOUT: %N.loc6_9.1: %i32 = bind_symbolic_name N, 0, %N.param [symbolic = %N.loc6_9.2 (constants.%N.51e)] // CHECK:STDOUT: } // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] { // CHECK:STDOUT: %a.patt: %ptr.b65 = binding_pattern a // CHECK:STDOUT: %a.param_patt: %ptr.b65 = value_param_pattern %a.patt, runtime_param0 // CHECK:STDOUT: } { // CHECK:STDOUT: %a.param: %ptr.b65 = value_param runtime_param0 // CHECK:STDOUT: %.loc15_13: type = splice_block %ptr.loc15 [template = constants.%ptr.b65] { // CHECK:STDOUT: %A.ref: %A.type = name_ref A, file.%A.decl [template = constants.%A.generic] // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6] // CHECK:STDOUT: %impl.elem0: %.a0b = impl_witness_access constants.%impl_witness.d39, element0 [template = constants.%Convert.956] // CHECK:STDOUT: %bound_method: = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound.d04] // CHECK:STDOUT: %specific_fn: = specific_function %bound_method, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.d62] // CHECK:STDOUT: %int.convert_checked: init %i32 = call %specific_fn(%int_0) [template = constants.%int_0.6a9] // CHECK:STDOUT: %.loc15_12.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_0.6a9] // CHECK:STDOUT: %.loc15_12.2: %i32 = converted %int_0, %.loc15_12.1 [template = constants.%int_0.6a9] // CHECK:STDOUT: %A: type = class_type @A, @A(constants.%int_0.6a9) [template = constants.%A.6fc] // CHECK:STDOUT: %ptr.loc15: type = ptr_type %A.6fc [template = constants.%ptr.b65] // CHECK:STDOUT: } // CHECK:STDOUT: %a: %ptr.b65 = bind_name a, %a.param // CHECK:STDOUT: } // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @B { // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template = constants.%complete_type.357] // CHECK:STDOUT: complete_type_witness = %complete_type // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = constants.%B // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: generic class @A(%N.loc6_9.1: %i32) { // CHECK:STDOUT: %N.loc6_9.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc6_9.2 (constants.%N.51e)] // CHECK:STDOUT: %N.patt.loc6_9.2: %i32 = symbolic_binding_pattern N, 0 [symbolic = %N.patt.loc6_9.2 (constants.%N.patt.8e2)] // CHECK:STDOUT: // CHECK:STDOUT: !definition: // CHECK:STDOUT: %A: type = class_type @A, @A(%N.loc6_9.2) [symbolic = %A (constants.%A.dd3)] // CHECK:STDOUT: %A.elem.loc7: type = unbound_element_type @A.%A (%A.dd3), %B [symbolic = %A.elem.loc7 (constants.%A.elem.500)] // CHECK:STDOUT: %Convert.bound: = bound_method %N.loc6_9.2, constants.%Convert.960 [symbolic = %Convert.bound (constants.%Convert.bound.588)] // CHECK:STDOUT: %Convert.specific_fn: = specific_function %Convert.bound, @Convert.3(constants.%int_32) [symbolic = %Convert.specific_fn (constants.%Convert.specific_fn.18b)] // CHECK:STDOUT: %int.convert_checked: init Core.IntLiteral = call %Convert.specific_fn(%N.loc6_9.2) [symbolic = %int.convert_checked (constants.%int.convert_checked)] // CHECK:STDOUT: %iN.builtin: type = int_type signed, %int.convert_checked [symbolic = %iN.builtin (constants.%iN.builtin.c5d)] // CHECK:STDOUT: %require_complete: = require_complete_type @A.%iN.builtin (%iN.builtin.c5d) [symbolic = %require_complete (constants.%require_complete.be5)] // CHECK:STDOUT: %A.elem.loc12: type = unbound_element_type @A.%A (%A.dd3), @A.%iN.builtin (%iN.builtin.c5d) [symbolic = %A.elem.loc12 (constants.%A.elem.d60)] // CHECK:STDOUT: %struct_type.base.n: type = struct_type {.base: %B, .n: @A.%iN.builtin (%iN.builtin.c5d)} [symbolic = %struct_type.base.n (constants.%struct_type.base.n)] // CHECK:STDOUT: %complete_type.loc13_1.2: = complete_type_witness @A.%struct_type.base.n (%struct_type.base.n) [symbolic = %complete_type.loc13_1.2 (constants.%complete_type.547)] // CHECK:STDOUT: // CHECK:STDOUT: class { // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B] // CHECK:STDOUT: %.loc7: @A.%A.elem.loc7 (%A.elem.500) = base_decl %B.ref, element0 [template] // CHECK:STDOUT: %.loc12_8: @A.%A.elem.loc12 (%A.elem.d60) = field_decl n, element1 [template] // CHECK:STDOUT: name_binding_decl { // CHECK:STDOUT: %.loc12_3: @A.%A.elem.loc12 (%A.elem.d60) = var_pattern %.loc12_8 // CHECK:STDOUT: } // CHECK:STDOUT: %.var: ref @A.%A.elem.loc12 (%A.elem.d60) = var // CHECK:STDOUT: %complete_type.loc13_1.1: = complete_type_witness %struct_type.base.n [symbolic = %complete_type.loc13_1.2 (constants.%complete_type.547)] // CHECK:STDOUT: complete_type_witness = %complete_type.loc13_1.1 // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = constants.%A.dd3 // CHECK:STDOUT: .base = %.loc7 // CHECK:STDOUT: .n = %.loc12_8 // CHECK:STDOUT: extend %B.ref // CHECK:STDOUT: } // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @Int.1(%N.param_patt: Core.IntLiteral) -> type = "int.make_type_signed"; // CHECK:STDOUT: // CHECK:STDOUT: fn @F(%a.param_patt: %ptr.b65) { // CHECK:STDOUT: !entry: // CHECK:STDOUT: name_binding_decl { // CHECK:STDOUT: %b.patt: %ptr.e79 = binding_pattern b // CHECK:STDOUT: } // CHECK:STDOUT: %a.ref: %ptr.b65 = name_ref a, %a // CHECK:STDOUT: %.loc20_11: type = splice_block %ptr.loc20 [template = constants.%ptr.e79] { // CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [template = constants.%B] // CHECK:STDOUT: %ptr.loc20: type = ptr_type %B [template = constants.%ptr.e79] // CHECK:STDOUT: } // CHECK:STDOUT: %.loc20_15.1: ref %A.6fc = deref %a.ref // CHECK:STDOUT: %.loc20_15.2: ref %B = class_element_access %.loc20_15.1, element0 // CHECK:STDOUT: %addr: %ptr.e79 = addr_of %.loc20_15.2 // CHECK:STDOUT: %.loc20_15.3: %ptr.e79 = converted %a.ref, %addr // CHECK:STDOUT: %b: %ptr.e79 = bind_name b, %.loc20_15.3 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: specific @A(constants.%N.51e) { // CHECK:STDOUT: %N.loc6_9.2 => constants.%N.51e // CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%N.51e // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: specific @A(%N.loc6_9.2) {} // CHECK:STDOUT: // CHECK:STDOUT: specific @A(constants.%int_0.6a9) { // CHECK:STDOUT: %N.loc6_9.2 => constants.%int_0.6a9 // CHECK:STDOUT: %N.patt.loc6_9.2 => constants.%int_0.6a9 // CHECK:STDOUT: // CHECK:STDOUT: !definition: // CHECK:STDOUT: %A => constants.%A.6fc // CHECK:STDOUT: %A.elem.loc7 => constants.%A.elem.d81 // CHECK:STDOUT: %Convert.bound => constants.%Convert.bound.0fd // CHECK:STDOUT: %Convert.specific_fn => constants.%Convert.specific_fn.f3f // CHECK:STDOUT: %int.convert_checked => constants.%int_0.5c6 // CHECK:STDOUT: %iN.builtin => // CHECK:STDOUT: %require_complete => // CHECK:STDOUT: %A.elem.loc12 => // CHECK:STDOUT: %struct_type.base.n => // CHECK:STDOUT: %complete_type.loc13_1.2 => // CHECK:STDOUT: } // CHECK:STDOUT: