Parse vars in classes the same as vars in other locations (#7188)

Class vars are still restricted to simple `name: type` bindings, not
full patterns. This is now handled in the check phase instead of during
parsing.

This is in preparation for supporting `static var`.
This commit is contained in:
Nicholas Bishop
2026-05-13 21:22:46 +00:00
committed by GitHub
parent 5706601096
commit bd918fb33b
91 changed files with 370 additions and 660 deletions
+25 -7
View File
@@ -79,13 +79,9 @@ fn G[_:! type]() {}
library "[[@TEST_NAME]]";
class C {
// CHECK:STDERR: fail_class.carbon:[[@LINE+8]]:7: error: expected identifier in field declaration [ExpectedFieldIdentifier]
// CHECK:STDERR: fail_class.carbon:[[@LINE+4]]:7: error: expected identifier in field declaration [FieldNamedUnderscore]
// CHECK:STDERR: var _: ();
// CHECK:STDERR: ^
// CHECK:STDERR:
// CHECK:STDERR: fail_class.carbon:[[@LINE+4]]:3: error: semantics TODO: `handle invalid parse trees in `check`` [SemanticsTodo]
// CHECK:STDERR: var _: ();
// CHECK:STDERR: ^~~~~~~~~~
// CHECK:STDERR: ^~~~~
// CHECK:STDERR:
var _: ();
}
@@ -494,10 +490,32 @@ fn F() -> {} {
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %C: type = class_type @C [concrete]
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
// CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %empty_tuple.type [concrete]
// CHECK:STDOUT: %struct_type._: type = struct_type {._: %empty_tuple.type} [concrete]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type._ [concrete]
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: imports {
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
// CHECK:STDOUT: import Core//prelude
// CHECK:STDOUT: import Core//prelude/...
// CHECK:STDOUT: }
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: file {
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
// CHECK:STDOUT: .Core = imports.%Core
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: }
// CHECK:STDOUT: %Core.import = import Core
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
// CHECK:STDOUT: }
// CHECK:STDOUT:
// CHECK:STDOUT: class @C {
// CHECK:STDOUT: complete_type_witness = invalid
// CHECK:STDOUT: %.loc9: %C.elem = field_decl _, element0 [concrete]
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type._ [concrete = constants.%complete_type]
// CHECK:STDOUT: complete_type_witness = %complete_type
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%C