mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:20:11 +01:00
Retain the `ClassDeclaration` node to represent a syntactic declaration of a class (including possibly a declaration of a generic class), but use a separate SemIR node to represent the class type itself. This allows us to give the two separate treatment. The `ClassDeclaration` is still entered into the name lookup table for its enclosing scope, but when it is named in an expression, the class type is produced instead. When the class declaration is named in a declaration name, it can be used to define members of the class, but an expression that resolves to the class type cannot be used to define members of the class. In order to distinguish these cases, use `Name` rather than `NameExpression` for the left-hand side of a `QualifiedName` parse node. This removes the only use of the `Expression` form of a declaration name, so that is also removed. In the future, `ClassType` will also be used to describe types such as `Vector(T)`, for which there is no corresponding `ClassDeclaration`.
40 lines
1.8 KiB
Plaintext
40 lines
1.8 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 Incomplete;
|
|
|
|
// CHECK:STDERR: fail_incomplete_element.carbon:[[@LINE+6]]:22: ERROR: Variable has incomplete type `[Incomplete; 1]`.
|
|
// CHECK:STDERR: var a: [Incomplete; 1];
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR: fail_incomplete_element.carbon:[[@LINE-5]]:1: Class was forward declared here.
|
|
// CHECK:STDERR: class Incomplete;
|
|
// CHECK:STDERR: ^
|
|
var a: [Incomplete; 1];
|
|
|
|
// CHECK:STDERR: fail_incomplete_element.carbon:[[@LINE+3]]:27: ERROR: Cannot implicitly convert from `<error>*` to `Incomplete*`.
|
|
// CHECK:STDERR: var p: Incomplete* = &a[0];
|
|
// CHECK:STDERR: ^
|
|
var p: Incomplete* = &a[0];
|
|
|
|
// CHECK:STDOUT: file "fail_incomplete_element.carbon" {
|
|
// CHECK:STDOUT: class_declaration @Incomplete, ()
|
|
// CHECK:STDOUT: %Incomplete: type = class_type @Incomplete
|
|
// CHECK:STDOUT: %Incomplete.ref.loc15: type = name_reference "Incomplete", %Incomplete
|
|
// CHECK:STDOUT: %.loc15_21: i32 = int_literal 1
|
|
// CHECK:STDOUT: %.loc15_22: type = array_type %.loc15_21, Incomplete
|
|
// CHECK:STDOUT: %a: ref <error> = var "a"
|
|
// CHECK:STDOUT: %Incomplete.ref.loc20: type = name_reference "Incomplete", %Incomplete
|
|
// CHECK:STDOUT: %.loc20_18: type = ptr_type Incomplete
|
|
// CHECK:STDOUT: %p: ref Incomplete* = var "p"
|
|
// CHECK:STDOUT: %a.ref: ref <error> = name_reference "a", %a
|
|
// CHECK:STDOUT: %.loc20_25: i32 = int_literal 0
|
|
// CHECK:STDOUT: %.loc20_22.1: type = ptr_type <error>
|
|
// CHECK:STDOUT: %.loc20_22.2: <error>* = address_of <error>
|
|
// CHECK:STDOUT: assign %p, <error>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @Incomplete;
|