| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- // 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/redeclare.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/generic/redeclare.carbon
- // --- valid.carbon
- library "valid";
- class Generic(T:! type);
- class Generic(T:! type) {
- }
- // --- fail_mismatch_param_list.carbon
- library "mismatch_param_list";
- class A;
- // CHECK:STDERR: fail_mismatch_param_list.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of parameter list.
- // CHECK:STDERR: class A(T:! type) {}
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
- // CHECK:STDERR: fail_mismatch_param_list.carbon:[[@LINE-4]]:1: Previously declared without parameter list.
- // CHECK:STDERR: class A;
- // CHECK:STDERR: ^~~~~~~~
- // CHECK:STDERR:
- class A(T:! type) {}
- // --- fail_mismatch_implicit_param_list.carbon
- library "implicit_mismatch_param_list";
- class B(N:! i32);
- // CHECK:STDERR: fail_mismatch_implicit_param_list.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of implicit parameter list.
- // CHECK:STDERR: class B[T:! type](N:! T) {}
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~
- // CHECK:STDERR: fail_mismatch_implicit_param_list.carbon:[[@LINE-4]]:1: Previously declared without implicit parameter list.
- // CHECK:STDERR: class B(N:! i32);
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
- // CHECK:STDERR:
- class B[T:! type](N:! T) {}
- // --- fail_mismatch_param_count.carbon
- library "mismatch_param_count";
- class C(T:! type);
- // CHECK:STDERR: fail_mismatch_param_count.carbon:[[@LINE+7]]:1: ERROR: Redeclaration differs because of parameter count of 2.
- // CHECK:STDERR: class C(T:! type, U:! i32) {}
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
- // CHECK:STDERR: fail_mismatch_param_count.carbon:[[@LINE-4]]:1: Previously declared with parameter count of 1.
- // CHECK:STDERR: class C(T:! type);
- // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
- // CHECK:STDERR:
- class C(T:! type, U:! i32) {}
- // --- fail_mismatch_param_type.carbon
- library "mismatch_param_type";
- class D(T:! type);
- // CHECK:STDERR: fail_mismatch_param_type.carbon:[[@LINE+7]]:9: ERROR: Redeclaration differs at parameter 1.
- // CHECK:STDERR: class D(T:! i32) {}
- // CHECK:STDERR: ^
- // CHECK:STDERR: fail_mismatch_param_type.carbon:[[@LINE-4]]:9: Previous declaration's corresponding parameter here.
- // CHECK:STDERR: class D(T:! type);
- // CHECK:STDERR: ^
- // CHECK:STDERR:
- class D(T:! i32) {}
- // --- fail_mismatch_param_name.carbon
- library "mismatch_param_name";
- class E(T:! type);
- // CHECK:STDERR: fail_mismatch_param_name.carbon:[[@LINE+6]]:9: ERROR: Redeclaration differs at parameter 1.
- // CHECK:STDERR: class E(U:! type) {}
- // CHECK:STDERR: ^
- // CHECK:STDERR: fail_mismatch_param_name.carbon:[[@LINE-4]]:9: Previous declaration's corresponding parameter here.
- // CHECK:STDERR: class E(T:! type);
- // CHECK:STDERR: ^
- class E(U:! type) {}
- // CHECK:STDOUT: --- valid.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %Generic.type: type = generic_class_type @Generic [template]
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %Generic.1: %Generic.type = struct_value () [template]
- // CHECK:STDOUT: %Generic.2: type = class_type @Generic, (%T) [symbolic]
- // CHECK:STDOUT: %.2: type = struct_type {} [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .Generic = %Generic.decl.loc4
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
- // CHECK:STDOUT: %Generic.decl.loc4: %Generic.type = class_decl @Generic [template = constants.%Generic.1] {
- // CHECK:STDOUT: %T.loc4_15.1: type = param T
- // CHECK:STDOUT: %T.loc4_15.2: type = bind_symbolic_name T 0, %T.loc4_15.1 [symbolic = constants.%T]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Generic.decl.loc6: %Generic.type = class_decl @Generic [template = constants.%Generic.1] {
- // CHECK:STDOUT: %T.loc6_15.1: type = param T
- // CHECK:STDOUT: %T.loc6_15.2: type = bind_symbolic_name T 0, %T.loc6_15.1 [symbolic = constants.%T]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @Generic
- // CHECK:STDOUT: generic [file.%T.loc4_15.2: type] {
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%Generic.2
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_mismatch_param_list.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %A: type = class_type @A [template]
- // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %.2: %.type = struct_value () [template]
- // CHECK:STDOUT: %.3: type = class_type @.1, (%T) [symbolic]
- // CHECK:STDOUT: %.4: type = struct_type {} [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .A = %A.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
- // CHECK:STDOUT: %A.decl: type = class_decl @A [template = constants.%A] {}
- // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
- // CHECK:STDOUT: %T.loc12_9.1: type = param T
- // CHECK:STDOUT: %T.loc12_9.2: type = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @A;
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @.1
- // CHECK:STDOUT: generic [file.%T.loc12_9.2: type] {
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%.3
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_mismatch_implicit_param_list.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %N.1: i32 = bind_symbolic_name N 0 [symbolic]
- // CHECK:STDOUT: %B.type: type = generic_class_type @B [template]
- // CHECK:STDOUT: %B.1: %B.type = struct_value () [template]
- // CHECK:STDOUT: %B.2: type = class_type @B, (%N.1) [symbolic]
- // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %N.2: %T = bind_symbolic_name N 1 [symbolic]
- // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
- // CHECK:STDOUT: %.2: %.type = struct_value () [template]
- // CHECK:STDOUT: %.3: type = class_type @.1, (%T, %N.2) [symbolic]
- // CHECK:STDOUT: %.4: type = struct_type {} [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .B = %B.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
- // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
- // CHECK:STDOUT: %B.decl: %B.type = class_decl @B [template = constants.%B.1] {
- // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
- // CHECK:STDOUT: %.loc4_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
- // CHECK:STDOUT: %.loc4_13.2: type = converted %int.make_type_32, %.loc4_13.1 [template = i32]
- // CHECK:STDOUT: %N.loc4_9.1: i32 = param N
- // CHECK:STDOUT: %N.loc4_9.2: i32 = bind_symbolic_name N 0, %N.loc4_9.1 [symbolic = constants.%N.1]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
- // CHECK:STDOUT: %T.loc12_9.1: type = param T
- // CHECK:STDOUT: %T.loc12_9.2: type = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T]
- // CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc12_9.2 [symbolic = constants.%T]
- // CHECK:STDOUT: %N.loc12_19.1: %T = param N
- // CHECK:STDOUT: %N.loc12_19.2: %T = bind_symbolic_name N 1, %N.loc12_19.1 [symbolic = constants.%N.2]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @B
- // CHECK:STDOUT: generic [file.%N.loc4_9.2: i32];
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @.1
- // CHECK:STDOUT: generic [file.%T.loc12_9.2: type, file.%N.loc12_19.2: %T] {
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%.3
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_mismatch_param_count.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %C.type: type = generic_class_type @C [template]
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %C.1: %C.type = struct_value () [template]
- // CHECK:STDOUT: %C.2: type = class_type @C, (%T) [symbolic]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %U: i32 = bind_symbolic_name U 1 [symbolic]
- // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
- // CHECK:STDOUT: %.2: %.type = struct_value () [template]
- // CHECK:STDOUT: %.3: type = class_type @.1, (%T, %U) [symbolic]
- // CHECK:STDOUT: %.4: type = struct_type {} [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .C = %C.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
- // CHECK:STDOUT: %C.decl: %C.type = class_decl @C [template = constants.%C.1] {
- // CHECK:STDOUT: %T.loc4_9.1: type = param T
- // CHECK:STDOUT: %T.loc4_9.2: type = bind_symbolic_name T 0, %T.loc4_9.1 [symbolic = constants.%T]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
- // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
- // CHECK:STDOUT: %T.loc12_9.1: type = param T
- // CHECK:STDOUT: %T.loc12_9.2: type = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T]
- // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
- // CHECK:STDOUT: %.loc12_23.1: type = value_of_initializer %int.make_type_32 [template = i32]
- // CHECK:STDOUT: %.loc12_23.2: type = converted %int.make_type_32, %.loc12_23.1 [template = i32]
- // CHECK:STDOUT: %U.loc12_19.1: i32 = param U
- // CHECK:STDOUT: %U.loc12_19.2: i32 = bind_symbolic_name U 1, %U.loc12_19.1 [symbolic = constants.%U]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @C
- // CHECK:STDOUT: generic [file.%T.loc4_9.2: type];
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @.1
- // CHECK:STDOUT: generic [file.%T.loc12_9.2: type, file.%U.loc12_19.2: i32] {
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%.3
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_mismatch_param_type.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %T.1: type = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %D.type: type = generic_class_type @D [template]
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %D.1: %D.type = struct_value () [template]
- // CHECK:STDOUT: %D.2: type = class_type @D, (%T.1) [symbolic]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %T.2: i32 = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
- // CHECK:STDOUT: %.2: %.type = struct_value () [template]
- // CHECK:STDOUT: %.3: type = class_type @.1, (%T.2) [symbolic]
- // CHECK:STDOUT: %.4: type = struct_type {} [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .D = %D.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
- // CHECK:STDOUT: %D.decl: %D.type = class_decl @D [template = constants.%D.1] {
- // CHECK:STDOUT: %T.loc4_9.1: type = param T
- // CHECK:STDOUT: %T.loc4_9.2: type = bind_symbolic_name T 0, %T.loc4_9.1 [symbolic = constants.%T.1]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %import_ref: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
- // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
- // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
- // CHECK:STDOUT: %.loc12_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
- // CHECK:STDOUT: %.loc12_13.2: type = converted %int.make_type_32, %.loc12_13.1 [template = i32]
- // CHECK:STDOUT: %T.loc12_9.1: i32 = param T
- // CHECK:STDOUT: %T.loc12_9.2: i32 = bind_symbolic_name T 0, %T.loc12_9.1 [symbolic = constants.%T.2]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @D
- // CHECK:STDOUT: generic [file.%T.loc4_9.2: type];
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @.1
- // CHECK:STDOUT: generic [file.%T.loc12_9.2: i32] {
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%.3
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_mismatch_param_name.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %T: type = bind_symbolic_name T 0 [symbolic]
- // CHECK:STDOUT: %E.type: type = generic_class_type @E [template]
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %E.1: %E.type = struct_value () [template]
- // CHECK:STDOUT: %E.2: type = class_type @E, (%T) [symbolic]
- // CHECK:STDOUT: %U: type = bind_symbolic_name U 0 [symbolic]
- // CHECK:STDOUT: %.type: type = generic_class_type @.1 [template]
- // CHECK:STDOUT: %.2: %.type = struct_value () [template]
- // CHECK:STDOUT: %.3: type = class_type @.1, (%U) [symbolic]
- // CHECK:STDOUT: %.4: type = struct_type {} [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .E = %E.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
- // CHECK:STDOUT: %E.decl: %E.type = class_decl @E [template = constants.%E.1] {
- // CHECK:STDOUT: %T.loc4_9.1: type = param T
- // CHECK:STDOUT: %T.loc4_9.2: type = bind_symbolic_name T 0, %T.loc4_9.1 [symbolic = constants.%T]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %.decl: %.type = class_decl @.1 [template = constants.%.2] {
- // CHECK:STDOUT: %U.loc11_9.1: type = param U
- // CHECK:STDOUT: %U.loc11_9.2: type = bind_symbolic_name U 0, %U.loc11_9.1 [symbolic = constants.%U]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @E
- // CHECK:STDOUT: generic [file.%T.loc4_9.2: type];
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @.1
- // CHECK:STDOUT: generic [file.%U.loc11_9.2: type] {
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%.3
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|