diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -954,6 +954,7 @@ kw_event = &IdentTable.get("event"); kw_fixed = &IdentTable.get("fixed"); kw_foreach = &IdentTable.get("foreach"); + kw_init = &IdentTable.get("init"); kw_implicit = &IdentTable.get("implicit"); kw_internal = &IdentTable.get("internal"); kw_lock = &IdentTable.get("lock"); @@ -986,11 +987,11 @@ CSharpExtraKeywords = std::unordered_set( {kw_base, kw_byte, kw_checked, kw_decimal, kw_delegate, kw_event, - kw_fixed, kw_foreach, kw_implicit, kw_in, kw_interface, kw_internal, - kw_is, kw_lock, kw_null, kw_object, kw_out, kw_override, kw_params, - kw_readonly, kw_ref, kw_string, kw_stackalloc, kw_sbyte, kw_sealed, - kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort, kw_when, - kw_where, + kw_fixed, kw_foreach, kw_implicit, kw_in, kw_init, kw_interface, + kw_internal, kw_is, kw_lock, kw_null, kw_object, kw_out, kw_override, + kw_params, kw_readonly, kw_ref, kw_string, kw_stackalloc, kw_sbyte, + kw_sealed, kw_uint, kw_ulong, kw_unchecked, kw_unsafe, kw_ushort, + kw_when, kw_where, // Keywords from the JavaScript section. kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from, kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly, @@ -1078,6 +1079,7 @@ IdentifierInfo *kw_fixed; IdentifierInfo *kw_foreach; IdentifierInfo *kw_implicit; + IdentifierInfo *kw_init; IdentifierInfo *kw_internal; IdentifierInfo *kw_lock; diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1839,14 +1839,14 @@ // A trivial property accessor is of the form: // { [ACCESS_SPECIFIER] [get]; [ACCESS_SPECIFIER] [set] } // Track these as they do not require line breaks to be introduced. - bool HasGetOrSet = false; + bool HasAccessSpecifier = false; bool IsTrivialPropertyAccessor = true; while (!eof()) { if (Tok->isOneOf(tok::semi, tok::kw_public, tok::kw_private, - tok::kw_protected, Keywords.kw_internal, Keywords.kw_get, - Keywords.kw_set)) { - if (Tok->isOneOf(Keywords.kw_get, Keywords.kw_set)) - HasGetOrSet = true; + tok::kw_protected, Keywords.kw_internal, Keywords.kw_init, + Keywords.kw_get, Keywords.kw_set)) { + if (Tok->isOneOf(Keywords.kw_get, Keywords.kw_init, Keywords.kw_set)) + HasAccessSpecifier = true; Tok = Tokens->getNextToken(); continue; } @@ -1855,7 +1855,7 @@ break; } - if (!HasGetOrSet) { + if (!HasAccessSpecifier) { Tokens->setPosition(StoredPosition); return false; } diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -960,9 +960,11 @@ verifyFormat("int Value { get; } = 0", Style); verifyFormat("int Value { set }", Style); verifyFormat("int Value { set; }", Style); + verifyFormat("int Value { init; }", Style); verifyFormat("int Value { internal set; }", Style); verifyFormat("int Value { set; } = 0", Style); verifyFormat("int Value { get; set }", Style); + verifyFormat("int Value { get; init; }", Style); verifyFormat("int Value { set; get }", Style); verifyFormat("int Value { get; private set; }", Style); verifyFormat("int Value { get; set; }", Style);