Files
carbon-lang/toolchain/check/testdata/class/fail_redeclaration_introducer.carbon
T
Richard Smith 67d5446b03 Add Self to the name scope for a class. (#3736)
Rather than just adding `Self` to the lexical scope, add it to the
class's name scope so that it is visible in later lexical scopes for the
same class -- in particular, for out-of-line definitions of members.
Also switch some tests in `check/testdata/class` over to making
idiomatic use of `Self` both inside a class and out-of-line, now that it
works more consistently.

Note that this does not permit using `Class.Self`, but only because we
don't yet support keyword names after `.` at all. If that changed, one
could use `Class.Self` to redundantly refer to `Class`. Whether we allow
that is left to a future decision.
2024-02-29 21:33:47 +00:00

152 lines
6.1 KiB
Plaintext

// 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
class A;
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: base class A {}
// CHECK:STDERR: ^~~~~~~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-4]]:1: Previously declared here.
// CHECK:STDERR: class A;
// CHECK:STDERR: ^~~~~~~~
base class A {}
class B;
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: abstract class B {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-4]]:1: Previously declared here.
// CHECK:STDERR: class B;
// CHECK:STDERR: ^~~~~~~~
abstract class B {}
base class C;
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: class C {}
// CHECK:STDERR: ^~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-4]]:1: Previously declared here.
// CHECK:STDERR: base class C;
// CHECK:STDERR: ^~~~~~~~~~~~~
class C {}
base class D;
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: abstract class D {}
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-4]]:1: Previously declared here.
// CHECK:STDERR: base class D;
// CHECK:STDERR: ^~~~~~~~~~~~~
abstract class D {}
abstract class E;
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: class E {}
// CHECK:STDERR: ^~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-4]]:1: Previously declared here.
// CHECK:STDERR: abstract class E;
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
class E {}
abstract class F;
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: base class F {}
// CHECK:STDERR: ^~~~~~~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-4]]:1: Previously declared here.
// CHECK:STDERR: abstract class F;
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
base class F {}
class G {}
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: abstract class G;
// CHECK:STDERR: ^~~~~~~~~~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-4]]:1: Previously declared here.
// CHECK:STDERR: class G {}
// CHECK:STDERR: ^~~~~~~~~
abstract class G;
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE+6]]:1: ERROR: Class redeclared with different inheritance kind.
// CHECK:STDERR: base class G;
// CHECK:STDERR: ^~~~~~~~~~~~~
// CHECK:STDERR: fail_redeclaration_introducer.carbon:[[@LINE-11]]:1: Previously declared here.
// CHECK:STDERR: class G {}
// CHECK:STDERR: ^~~~~~~~~
base class G;
// CHECK:STDOUT: --- fail_redeclaration_introducer.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %A: type = class_type @A [template]
// CHECK:STDOUT: %.1: type = struct_type {} [template]
// CHECK:STDOUT: %B: type = class_type @B [template]
// CHECK:STDOUT: %C: type = class_type @C [template]
// CHECK:STDOUT: %D: type = class_type @D [template]
// CHECK:STDOUT: %E: type = class_type @E [template]
// CHECK:STDOUT: %F: type = class_type @F [template]
// CHECK:STDOUT: %G: type = class_type @G [template]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace {
// CHECK:STDOUT: .A = %A.decl.loc7
// CHECK:STDOUT: .B = %B.decl.loc16
// CHECK:STDOUT: .C = %C.decl.loc25
// CHECK:STDOUT: .D = %D.decl.loc34
// CHECK:STDOUT: .E = %E.decl.loc43
// CHECK:STDOUT: .F = %F.decl.loc52
// CHECK:STDOUT: .G = %G.decl.loc61
// CHECK:STDOUT: } [template]
// CHECK:STDOUT: %A.decl.loc7 = class_decl @A {} [template = constants.%A]
// CHECK:STDOUT: %A.decl.loc14 = class_decl @A {} [template = constants.%A]
// CHECK:STDOUT: %B.decl.loc16 = class_decl @B {} [template = constants.%B]
// CHECK:STDOUT: %B.decl.loc23 = class_decl @B {} [template = constants.%B]
// CHECK:STDOUT: %C.decl.loc25 = class_decl @C {} [template = constants.%C]
// CHECK:STDOUT: %C.decl.loc32 = class_decl @C {} [template = constants.%C]
// CHECK:STDOUT: %D.decl.loc34 = class_decl @D {} [template = constants.%D]
// CHECK:STDOUT: %D.decl.loc41 = class_decl @D {} [template = constants.%D]
// CHECK:STDOUT: %E.decl.loc43 = class_decl @E {} [template = constants.%E]
// CHECK:STDOUT: %E.decl.loc50 = class_decl @E {} [template = constants.%E]
// CHECK:STDOUT: %F.decl.loc52 = class_decl @F {} [template = constants.%F]
// CHECK:STDOUT: %F.decl.loc59 = class_decl @F {} [template = constants.%F]
// CHECK:STDOUT: %G.decl.loc61 = class_decl @G {} [template = constants.%G]
// CHECK:STDOUT: %G.decl.loc68 = class_decl @G {} [template = constants.%G]
// CHECK:STDOUT: %G.decl.loc75 = class_decl @G {} [template = constants.%G]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @A {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%A
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @B {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%B
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%C
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @D {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%D
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @E {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%E
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @F {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%F
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @G {
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%G
// CHECK:STDOUT: }
// CHECK:STDOUT: