|
| 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 | +// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon |
| 6 | +// |
| 7 | +// AUTOUPDATE |
| 8 | +// TIP: To test this file alone, run: |
| 9 | +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/generic/extend_type_completion.carbon |
| 10 | +// TIP: To dump output, run: |
| 11 | +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/generic/extend_type_completion.carbon |
| 12 | + |
| 13 | +// --- class_impl_doesnt_need_complete_interface.carbon |
| 14 | +library "[[@TEST_NAME]]"; |
| 15 | + |
| 16 | +interface K(T:! type) {} |
| 17 | + |
| 18 | +class C(N:! i32) { |
| 19 | + impl as K(array(i32, N)) {} |
| 20 | +} |
| 21 | + |
| 22 | +// C does not extend K so the type of K is not completed. No error. |
| 23 | +var v: C(-1); |
| 24 | + |
| 25 | +// --- fail_class_extend_impl_does_need_complete_interface.carbon |
| 26 | +library "[[@TEST_NAME]]"; |
| 27 | + |
| 28 | +interface K(T:! type) {} |
| 29 | + |
| 30 | +class C(N:! i32) { |
| 31 | + // CHECK:STDERR: fail_class_extend_impl_does_need_complete_interface.carbon:[[@LINE+3]]:18: error: array bound of -1 is negative [ArrayBoundNegative] |
| 32 | + // CHECK:STDERR: extend impl as K(array(i32, N)) {} |
| 33 | + // CHECK:STDERR: ^~~~~~~~~~~~~~~~ |
| 34 | + extend impl as K(array(i32, N)) {} |
| 35 | +} |
| 36 | + |
| 37 | +// C extends K so the type of K is completed, but is invalid. |
| 38 | +// CHECK:STDERR: fail_class_extend_impl_does_need_complete_interface.carbon:[[@LINE+4]]:8: note: in `C(-1)` used here [ResolvingSpecificHere] |
| 39 | +// CHECK:STDERR: var v: C(-1); |
| 40 | +// CHECK:STDERR: ^~~~~ |
| 41 | +// CHECK:STDERR: |
| 42 | +var v: C(-1); |
| 43 | + |
| 44 | +// --- interface_require_impls_doesnt_need_complete_interface.carbon |
| 45 | +library "[[@TEST_NAME]]"; |
| 46 | + |
| 47 | +interface K(T:! type) {} |
| 48 | +interface J(N:! i32) { |
| 49 | + require impls K(array(i32, N)); |
| 50 | +} |
| 51 | + |
| 52 | +// J does not extend K so the type of K is not completed. No error. |
| 53 | +var v: J(-1); |
| 54 | + |
| 55 | +// --- fail_interface_extend_require_impls_does_need_complete_interface.carbon |
| 56 | +library "[[@TEST_NAME]]"; |
| 57 | + |
| 58 | +interface K(T:! type) {} |
| 59 | +interface J(N:! i32) { |
| 60 | + // CHECK:STDERR: fail_interface_extend_require_impls_does_need_complete_interface.carbon:[[@LINE+3]]:37: error: array bound of -1 is negative [ArrayBoundNegative] |
| 61 | + // CHECK:STDERR: extend require impls K(array(i32, N)); |
| 62 | + // CHECK:STDERR: ^ |
| 63 | + extend require impls K(array(i32, N)); |
| 64 | +} |
| 65 | + |
| 66 | +// J extends K so the type of K is completed, but is invalid. |
| 67 | +// |
| 68 | +// TODO: The error location should be the type, like in the class case above. We |
| 69 | +// need a location for the type in context.bind_name_map() to use as the |
| 70 | +// location to Convert(). |
| 71 | +// |
| 72 | +// CHECK:STDERR: fail_interface_extend_require_impls_does_need_complete_interface.carbon:[[@LINE+4]]:1: note: in `require` used here [ResolvingSpecificHere] |
| 73 | +// CHECK:STDERR: var v: J(-1); |
| 74 | +// CHECK:STDERR: ^~~~~~~~~~~~ |
| 75 | +// CHECK:STDERR: |
| 76 | +var v: J(-1); |
| 77 | + |
| 78 | +// --- constraint_require_impls_doesnt_need_complete_interface.carbon |
| 79 | +library "[[@TEST_NAME]]"; |
| 80 | + |
| 81 | +interface K(T:! type) {} |
| 82 | +constraint J(N:! i32) { |
| 83 | + require impls K(array(i32, N)); |
| 84 | +} |
| 85 | + |
| 86 | +// J does not extend K so the type of K is not completed. No error. |
| 87 | +var v: J(-1); |
| 88 | + |
| 89 | +// --- fail_constraint_extend_require_impls_does_need_complete_interface.carbon |
| 90 | +library "[[@TEST_NAME]]"; |
| 91 | + |
| 92 | +interface K(T:! type) {} |
| 93 | +constraint J(N:! i32) { |
| 94 | + // CHECK:STDERR: fail_constraint_extend_require_impls_does_need_complete_interface.carbon:[[@LINE+3]]:37: error: array bound of -1 is negative [ArrayBoundNegative] |
| 95 | + // CHECK:STDERR: extend require impls K(array(i32, N)); |
| 96 | + // CHECK:STDERR: ^ |
| 97 | + extend require impls K(array(i32, N)); |
| 98 | +} |
| 99 | + |
| 100 | +// J extends K so the type of K is completed, but is invalid. |
| 101 | +// CHECK:STDERR: fail_constraint_extend_require_impls_does_need_complete_interface.carbon:[[@LINE+4]]:1: note: in `require` used here [ResolvingSpecificHere] |
| 102 | +// CHECK:STDERR: var v: J(-1); |
| 103 | +// CHECK:STDERR: ^~~~~~~~~~~~ |
| 104 | +// CHECK:STDERR: |
| 105 | +var v: J(-1); |
0 commit comments