|
| 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/convert.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/impl/using_invalid_interface.carbon |
| 10 | +// TIP: To dump output, run: |
| 11 | +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/using_invalid_interface.carbon |
| 12 | + |
| 13 | +// --- fail_invalid_interface.carbon |
| 14 | +library "[[@TEST_NAME]]"; |
| 15 | + |
| 16 | +interface I {} |
| 17 | + |
| 18 | +class ArgToI(T:! I) {} |
| 19 | + |
| 20 | +interface IMisuse { |
| 21 | + let Arg:! type; |
| 22 | + // CHECK:STDERR: fail_invalid_interface.carbon:[[@LINE+7]]:26: error: cannot convert type `Arg` into type implementing `I` [ConversionFailureTypeToFacet] |
| 23 | + // CHECK:STDERR: fn Op[self: Self]() -> ArgToI(Arg); |
| 24 | + // CHECK:STDERR: ^~~~~~~~~~~ |
| 25 | + // CHECK:STDERR: fail_invalid_interface.carbon:[[@LINE-7]]:14: note: initializing generic parameter `T` declared here [InitializingGenericParam] |
| 26 | + // CHECK:STDERR: class ArgToI(T:! I) {} |
| 27 | + // CHECK:STDERR: ^ |
| 28 | + // CHECK:STDERR: |
| 29 | + fn Op[self: Self]() -> ArgToI(Arg); |
| 30 | +} |
| 31 | + |
| 32 | +// --- fail_misusing_invalid_interface.carbon |
| 33 | +library "[[@TEST_NAME]]"; |
| 34 | +// This import boundary is significant. |
| 35 | +import library "invalid_interface"; |
| 36 | + |
| 37 | +class C { |
| 38 | + // CHECK:STDERR: fail_misusing_invalid_interface.carbon:[[@LINE+4]]:32: error: name `T` not found [NameNotFound] |
| 39 | + // CHECK:STDERR: impl as IMisuse where .Arg = T { |
| 40 | + // CHECK:STDERR: ^ |
| 41 | + // CHECK:STDERR: |
| 42 | + impl as IMisuse where .Arg = T { |
| 43 | + // CHECK:STDERR: fail_misusing_invalid_interface.carbon:[[@LINE+4]]:35: error: name `T` not found [NameNotFound] |
| 44 | + // CHECK:STDERR: fn Op[self: Self]() -> ArgToI(T) { |
| 45 | + // CHECK:STDERR: ^ |
| 46 | + // CHECK:STDERR: |
| 47 | + fn Op[self: Self]() -> ArgToI(T) { |
| 48 | + return {}; |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +// CHECK:STDERR: fail_misusing_invalid_interface.carbon:[[@LINE+8]]:21: error: missing object argument in method call [MissingObjectInMethodCall] |
| 54 | +// CHECK:STDERR: fn F(T:! IMisuse) { T.Op(); } |
| 55 | +// CHECK:STDERR: ^~~~~~ |
| 56 | +// CHECK:STDERR: fail_misusing_invalid_interface.carbon:[[@LINE-21]]:1: in import [InImport] |
| 57 | +// CHECK:STDERR: fail_invalid_interface.carbon:16:3: note: calling function declared here [InCallToFunction] |
| 58 | +// CHECK:STDERR: fn Op[self: Self]() -> ArgToI(Arg); |
| 59 | +// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 60 | +// CHECK:STDERR: |
| 61 | +fn F(T:! IMisuse) { T.Op(); } |
| 62 | + |
| 63 | +fn G() { |
| 64 | + var c: C; |
| 65 | + // CHECK:STDERR: fail_misusing_invalid_interface.carbon:[[@LINE+10]]:3: error: cannot implicitly convert non-type value of type `C` into type implementing `IMisuse` [ConversionFailureNonTypeToFacet] |
| 66 | + // CHECK:STDERR: F(c); |
| 67 | + // CHECK:STDERR: ^~~~ |
| 68 | + // CHECK:STDERR: fail_misusing_invalid_interface.carbon:[[@LINE+7]]:3: note: type `C` does not implement interface `Core.ImplicitAs(IMisuse)` [MissingImplInMemberAccessNote] |
| 69 | + // CHECK:STDERR: F(c); |
| 70 | + // CHECK:STDERR: ^~~~ |
| 71 | + // CHECK:STDERR: fail_misusing_invalid_interface.carbon:[[@LINE-10]]:6: note: initializing generic parameter `T` declared here [InitializingGenericParam] |
| 72 | + // CHECK:STDERR: fn F(T:! IMisuse) { T.Op(); } |
| 73 | + // CHECK:STDERR: ^ |
| 74 | + // CHECK:STDERR: |
| 75 | + F(c); |
| 76 | +} |
| 77 | + |
| 78 | +// --- fail_using_invalid_interface.carbon |
| 79 | +library "[[@TEST_NAME]]"; |
| 80 | +// This import boundary is significant. |
| 81 | +import library "invalid_interface"; |
| 82 | + |
| 83 | +class ArgC {} |
| 84 | + |
| 85 | +class C { |
| 86 | + impl as IMisuse where .Arg = ArgC { |
| 87 | + // CHECK:STDERR: fail_using_invalid_interface.carbon:[[@LINE+8]]:28: error: cannot convert type `ArgC` into type implementing `I` [ConversionFailureTypeToFacet] |
| 88 | + // CHECK:STDERR: fn Op[self: Self]() -> ArgToI(ArgC) { |
| 89 | + // CHECK:STDERR: ^~~~~~~~~~~~ |
| 90 | + // CHECK:STDERR: fail_using_invalid_interface.carbon:[[@LINE-9]]:1: in import [InImport] |
| 91 | + // CHECK:STDERR: fail_invalid_interface.carbon:5:14: note: initializing generic parameter `T` declared here [InitializingGenericParam] |
| 92 | + // CHECK:STDERR: class ArgToI(T:! I) {} |
| 93 | + // CHECK:STDERR: ^ |
| 94 | + // CHECK:STDERR: |
| 95 | + fn Op[self: Self]() -> ArgToI(ArgC) { |
| 96 | + return {}; |
| 97 | + } |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +// CHECK:STDERR: fail_using_invalid_interface.carbon:[[@LINE+8]]:21: error: missing object argument in method call [MissingObjectInMethodCall] |
| 102 | +// CHECK:STDERR: fn F(T:! IMisuse) { T.Op(); } |
| 103 | +// CHECK:STDERR: ^~~~~~ |
| 104 | +// CHECK:STDERR: fail_using_invalid_interface.carbon:[[@LINE-23]]:1: in import [InImport] |
| 105 | +// CHECK:STDERR: fail_invalid_interface.carbon:16:3: note: calling function declared here [InCallToFunction] |
| 106 | +// CHECK:STDERR: fn Op[self: Self]() -> ArgToI(Arg); |
| 107 | +// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 108 | +// CHECK:STDERR: |
| 109 | +fn F(T:! IMisuse) { T.Op(); } |
| 110 | + |
| 111 | +fn G() { |
| 112 | + var c: C; |
| 113 | + // CHECK:STDERR: fail_using_invalid_interface.carbon:[[@LINE+10]]:3: error: cannot implicitly convert non-type value of type `C` into type implementing `IMisuse` [ConversionFailureNonTypeToFacet] |
| 114 | + // CHECK:STDERR: F(c); |
| 115 | + // CHECK:STDERR: ^~~~ |
| 116 | + // CHECK:STDERR: fail_using_invalid_interface.carbon:[[@LINE+7]]:3: note: type `C` does not implement interface `Core.ImplicitAs(IMisuse)` [MissingImplInMemberAccessNote] |
| 117 | + // CHECK:STDERR: F(c); |
| 118 | + // CHECK:STDERR: ^~~~ |
| 119 | + // CHECK:STDERR: fail_using_invalid_interface.carbon:[[@LINE-10]]:6: note: initializing generic parameter `T` declared here [InitializingGenericParam] |
| 120 | + // CHECK:STDERR: fn F(T:! IMisuse) { T.Op(); } |
| 121 | + // CHECK:STDERR: ^ |
| 122 | + // CHECK:STDERR: |
| 123 | + F(c); |
| 124 | +} |
0 commit comments