| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- // 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/adapter/fail_adapt_bad_decl.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/adapter/fail_adapt_bad_decl.carbon
- // --- fail_not_type.carbon
- library "[[@TEST_NAME]]";
- class Bad {
- // CHECK:STDERR: fail_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `Core.IntLiteral` to `type` [ImplicitAsConversionFailure]
- // CHECK:STDERR: adapt 100;
- // CHECK:STDERR: ^~~~~~~~~~
- // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
- // CHECK:STDERR: adapt 100;
- // CHECK:STDERR: ^~~~~~~~~~
- // CHECK:STDERR:
- adapt 100;
- }
- // CHECK:STDERR: fail_not_type.carbon:[[@LINE+4]]:18: error: member name `F` not found in `Bad` [MemberNameNotFoundInScope]
- // CHECK:STDERR: fn Use(b: Bad) { b.F(); }
- // CHECK:STDERR: ^~~
- // CHECK:STDERR:
- fn Use(b: Bad) { b.F(); }
- // --- fail_extend_not_type.carbon
- library "[[@TEST_NAME]]";
- class Bad {
- // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+7]]:3: error: cannot implicitly convert from `Core.IntLiteral` to `type` [ImplicitAsConversionFailure]
- // CHECK:STDERR: extend adapt 100;
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
- // CHECK:STDERR: fail_extend_not_type.carbon:[[@LINE+4]]:3: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
- // CHECK:STDERR: extend adapt 100;
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
- // CHECK:STDERR:
- extend adapt 100;
- }
- // No diagnostic here, we don't know what names Bad has.
- fn Use(b: Bad) { b.F(); }
- // --- fail_repeated.carbon
- library "[[@TEST_NAME]]";
- class MultipleAdapts {
- adapt ();
- // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
- // CHECK:STDERR: adapt {};
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
- // CHECK:STDERR: adapt ();
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- adapt {};
- }
- class MultipleAdaptsSameType {
- adapt ();
- // CHECK:STDERR: fail_repeated.carbon:[[@LINE+7]]:3: error: multiple `adapt` declarations in class [AdaptDeclRepeated]
- // CHECK:STDERR: adapt ();
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR: fail_repeated.carbon:[[@LINE-4]]:3: note: previous `adapt` declaration is here [ClassSpecificDeclPrevious]
- // CHECK:STDERR: adapt ();
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- adapt ();
- }
- // --- fail_bad_scope.carbon
- library "[[@TEST_NAME]]";
- // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:1: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
- // CHECK:STDERR: adapt {};
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- adapt {};
- interface I {
- // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:3: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
- // CHECK:STDERR: adapt {};
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- adapt {};
- }
- class C {
- interface I {
- // CHECK:STDERR: fail_bad_scope.carbon:[[@LINE+4]]:5: error: `adapt` declaration outside class [ClassSpecificDeclOutsideClass]
- // CHECK:STDERR: adapt {};
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- adapt {};
- }
- }
- // CHECK:STDOUT: --- fail_not_type.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %Bad: type = class_type @Bad [template]
- // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template]
- // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
- // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .Bad = %Bad.decl
- // CHECK:STDOUT: .Use = %Use.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
- // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
- // CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
- // CHECK:STDOUT: %b.param_patt: %Bad = value_param_pattern %b.patt, runtime_param0
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %b.param: %Bad = value_param runtime_param0
- // CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
- // CHECK:STDOUT: %b: %Bad = bind_name b, %b.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @Bad {
- // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template = constants.%int_100]
- // CHECK:STDOUT: %.loc12: type = converted %int_100, <error> [template = <error>]
- // CHECK:STDOUT: adapt_decl <error> [template]
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness <error> [template = <error>]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%Bad
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
- // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_extend_not_type.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %Bad: type = class_type @Bad [template]
- // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template]
- // CHECK:STDOUT: %Use.type: type = fn_type @Use [template]
- // CHECK:STDOUT: %Use: %Use.type = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .Bad = %Bad.decl
- // CHECK:STDOUT: .Use = %Use.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %Bad.decl: type = class_decl @Bad [template = constants.%Bad] {} {}
- // CHECK:STDOUT: %Use.decl: %Use.type = fn_decl @Use [template = constants.%Use] {
- // CHECK:STDOUT: %b.patt: %Bad = binding_pattern b
- // CHECK:STDOUT: %b.param_patt: %Bad = value_param_pattern %b.patt, runtime_param0
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %b.param: %Bad = value_param runtime_param0
- // CHECK:STDOUT: %Bad.ref: type = name_ref Bad, file.%Bad.decl [template = constants.%Bad]
- // CHECK:STDOUT: %b: %Bad = bind_name b, %b.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @Bad {
- // CHECK:STDOUT: %int_100: Core.IntLiteral = int_value 100 [template = constants.%int_100]
- // CHECK:STDOUT: %.loc12: type = converted %int_100, <error> [template = <error>]
- // CHECK:STDOUT: adapt_decl <error> [template]
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness <error> [template = <error>]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%Bad
- // CHECK:STDOUT: extend <error>
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Use(%b.param_patt: %Bad) {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %b.ref: %Bad = name_ref b, %b
- // CHECK:STDOUT: %F.ref: <error> = name_ref F, <error> [template = <error>]
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_repeated.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %MultipleAdapts: type = class_type @MultipleAdapts [template]
- // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [template]
- // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_tuple.type [template]
- // CHECK:STDOUT: %MultipleAdaptsSameType: type = class_type @MultipleAdaptsSameType [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .MultipleAdapts = %MultipleAdapts.decl
- // CHECK:STDOUT: .MultipleAdaptsSameType = %MultipleAdaptsSameType.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %MultipleAdapts.decl: type = class_decl @MultipleAdapts [template = constants.%MultipleAdapts] {} {}
- // CHECK:STDOUT: %MultipleAdaptsSameType.decl: type = class_decl @MultipleAdaptsSameType [template = constants.%MultipleAdaptsSameType] {} {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @MultipleAdapts {
- // CHECK:STDOUT: %.loc5_10: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %.loc5_11: type = converted %.loc5_10, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: adapt_decl %.loc5_11 [template]
- // CHECK:STDOUT: %.loc13: %empty_struct_type = struct_literal ()
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_tuple.type [template = constants.%complete_type]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%MultipleAdapts
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @MultipleAdaptsSameType {
- // CHECK:STDOUT: %.loc17_10: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %.loc17_11: type = converted %.loc17_10, constants.%empty_tuple.type [template = constants.%empty_tuple.type]
- // CHECK:STDOUT: adapt_decl %.loc17_11 [template]
- // CHECK:STDOUT: %.loc25: %empty_tuple.type = tuple_literal ()
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_tuple.type [template = constants.%complete_type]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%MultipleAdaptsSameType
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_bad_scope.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
- // CHECK:STDOUT: %I.type.733: type = facet_type <@I.1> [template]
- // CHECK:STDOUT: %Self.826: %I.type.733 = bind_symbolic_name Self, 0 [symbolic]
- // CHECK:STDOUT: %C: type = class_type @C [template]
- // CHECK:STDOUT: %I.type.e30: type = facet_type <@I.2> [template]
- // CHECK:STDOUT: %Self.6ef: %I.type.e30 = bind_symbolic_name Self, 0 [symbolic]
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: import Core//prelude
- // CHECK:STDOUT: import Core//prelude/...
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .I = %I.decl
- // CHECK:STDOUT: .C = %C.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %.loc8: %empty_struct_type = struct_literal ()
- // CHECK:STDOUT: %I.decl: type = interface_decl @I.1 [template = constants.%I.type.733] {} {}
- // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: interface @I.1 {
- // CHECK:STDOUT: %Self: %I.type.733 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.826]
- // CHECK:STDOUT: %.loc15: %empty_struct_type = struct_literal ()
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = %Self
- // CHECK:STDOUT: witness = ()
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: interface @I.2 {
- // CHECK:STDOUT: %Self: %I.type.e30 = bind_symbolic_name Self, 0 [symbolic = constants.%Self.6ef]
- // CHECK:STDOUT: %.loc24: %empty_struct_type = struct_literal ()
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = %Self
- // CHECK:STDOUT: witness = ()
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @C {
- // CHECK:STDOUT: %I.decl: type = interface_decl @I.2 [template = constants.%I.type.e30] {} {}
- // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type]
- // CHECK:STDOUT: complete_type_witness = %complete_type
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%C
- // CHECK:STDOUT: .I = %I.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|