Skip to content

Commit e9d2ef6

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 837895a + 114ea29 commit e9d2ef6

File tree

4 files changed

+104
-45
lines changed

4 files changed

+104
-45
lines changed

include/swift/Parse/Parser.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,14 @@ class Parser {
690690
return Context.LangOpts.EnableExperimentalConcurrency;
691691
}
692692

693+
/// Returns true if a Swift declaration starts after the current token,
694+
/// otherwise returns false.
695+
bool isNextStartOfSwiftDecl() {
696+
BacktrackingScope backtrack(*this);
697+
consumeToken();
698+
return isStartOfSwiftDecl();
699+
}
700+
693701
public:
694702
InFlightDiagnostic diagnose(SourceLoc Loc, DiagRef Diag) {
695703
if (Diags.isDiagnosticPointsToFirstBadToken(Diag.getID()) &&

lib/Parse/ParseDecl.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,7 +2908,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
29082908
break;
29092909
}
29102910

2911-
consumeAttributeLParen();
2911+
auto LParenLoc = consumeAttributeLParen();
29122912

29132913
if (Tok.is(tok::code_complete)) {
29142914
if (CodeCompletionCallbacks) {
@@ -2920,27 +2920,42 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
29202920
}
29212921

29222922
// Parse the subject.
2923-
if (Tok.isContextualKeyword("set")) {
2924-
consumeToken();
2925-
} else {
2926-
diagnose(Loc, diag::attr_access_expected_set, AttrName);
2923+
if (!Tok.isContextualKeyword("set")) {
2924+
auto diag = diagnose(Loc, diag::attr_access_expected_set, AttrName);
29272925

2928-
// Minimal recovery: if there's a single token and then an r_paren,
2929-
// consume them both. If there's just an r_paren, consume that.
2930-
if (!consumeIf(tok::r_paren)) {
2931-
if (Tok.isNot(tok::l_paren) && peekToken().is(tok::r_paren)) {
2932-
consumeToken();
2933-
consumeToken(tok::r_paren);
2934-
}
2926+
if (Tok.is(tok::r_paren)) {
2927+
// Suggest `set` between empty parens e.g. `private()` -> `private(set)`
2928+
auto SetLoc = consumeToken(tok::r_paren);
2929+
diag.fixItInsert(SetLoc, "set");
2930+
} else if (!Tok.is(tok::l_paren) && peekToken().is(tok::r_paren)) {
2931+
// Suggest `set` in place of an invalid token between parens
2932+
// e.g. `private(<invalid>)` -> `private(set)`
2933+
auto SetLoc = consumeToken();
2934+
diag.fixItReplace(SetLoc, "set");
2935+
consumeToken(tok::r_paren);
2936+
} else if (isNextStartOfSwiftDecl()) {
2937+
// Suggest `set)` in place of an invalid token after l_paren followed by
2938+
// a valid declaration start.
2939+
// e.g. `private(<invalid> var x: Int` -> `private(set) var x: Int`
2940+
auto SetLoc = consumeToken();
2941+
diag.fixItReplace(SetLoc, "set)");
2942+
} else {
2943+
// Suggest `set)` after l_paren if not followed by a valid declaration
2944+
// e.g. `private( <invalid>` -> `private(set) <invalid>`
2945+
diag.fixItInsertAfter(LParenLoc, "set)");
29352946
}
2947+
29362948
return makeParserSuccess();
29372949
}
29382950

2951+
auto SubjectLoc = consumeToken();
2952+
29392953
AttrRange = SourceRange(Loc, Tok.getLoc());
29402954

29412955
if (!consumeIf(tok::r_paren)) {
29422956
diagnose(Loc, diag::attr_expected_rparen, AttrName,
2943-
DeclAttribute::isDeclModifier(DK));
2957+
DeclAttribute::isDeclModifier(DK))
2958+
.fixItInsertAfter(SubjectLoc, ")");
29442959
return makeParserSuccess();
29452960
}
29462961

test/attr/accessibility.swift

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,38 @@ package(set) // expected-note {{previous modifier specified here}}
6969
public(set) // expected-error {{multiple incompatible access-level modifiers specified}}
7070
public var customSetterDuplicateAttr3 = 0
7171

72-
private(get) // expected-error{{expected 'set' as subject of 'private' modifier}}
72+
private(get) // expected-error{{expected 'set' as subject of 'private' modifier}} {{9-12=set}}
7373
var invalidSubject = 0
7474

75-
private(42) // expected-error{{expected 'set' as subject of 'private' modifier}}
75+
private(42) // expected-error{{expected 'set' as subject of 'private' modifier}} {{9-11=set}}
7676
var invalidSubject2 = 0
7777

7878
private(a bunch of random tokens) // expected-error{{expected 'set' as subject of 'private' modifier}} expected-error{{expected declaration}}
7979
var invalidSubject3 = 0
8080

8181

82-
package(get) // expected-error{{expected 'set' as subject of 'package' modifier}}
82+
package(get) // expected-error{{expected 'set' as subject of 'package' modifier}} {{9-12=set}}
8383
var invalidSubject4 = 0
8484

85-
package(42) // expected-error{{expected 'set' as subject of 'package' modifier}}
85+
package(42) // expected-error{{expected 'set' as subject of 'package' modifier}} {{9-11=set}}
8686
var invalidSubject5 = 0
8787

88-
private(set // expected-error{{expected ')' in 'private' modifier}}
88+
private((())) // expected-error{{expected 'set' as subject of 'private' modifier}} expected-error{{expected declaration}}
89+
var invalidSubject6 = 0
90+
91+
private( missingFunc(_ x: Int) -> Bool // expected-error{{expected 'set' as subject of 'private' modifier}} {{9-9=set)}} expected-error{{expected declaration}}
92+
let independentVar1 = 0
93+
94+
private(set // expected-error{{expected ')' in 'private' modifier}} {{12-12=)}}
8995
var unterminatedSubject = 0
9096

91-
private(42 // expected-error{{expected 'set' as subject of 'private' modifier}} expected-error{{expected declaration}}
97+
private(42 // expected-error{{expected 'set' as subject of 'private' modifier}} {{9-11=set)}}
9298
var unterminatedInvalidSubject = 0
9399

94-
private() // expected-error{{expected 'set' as subject of 'private' modifier}}
100+
private() // expected-error{{expected 'set' as subject of 'private' modifier}} {{9-9=set}}
95101
var emptySubject = 0
96102

97-
private( // expected-error{{expected 'set' as subject of 'private' modifier}}
103+
private( // expected-error{{expected 'set' as subject of 'private' modifier}} {{9-9=set)}}
98104
var unterminatedEmptySubject = 0
99105

100106
// Check that the parser made it here.
@@ -341,3 +347,10 @@ package extension PkgGenericStruct where Param: InternalProto {} // expected-err
341347
extension PkgGenericStruct where Param: InternalProto {
342348
package func foo() {} // expected-error {{cannot declare a package instance method in an extension with internal requirements}} {{3-10=internal}}
343349
}
350+
351+
func f() {}
352+
private( // expected-error{{expected 'set' as subject of 'private' modifier}} {{9-9=set)}}
353+
if true { // expected-error{{expected declaration}} {{none}}
354+
f()
355+
}
356+
var unrelatedVar = "Swift"

utils/build.ps1

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,49 +117,72 @@ PS> .\Build.ps1 -WindowsSDKArchitectures x64 -ProductVersion 1.2.3 -Test foundat
117117
[CmdletBinding(PositionalBinding = $false)]
118118
param
119119
(
120+
# Build Paths
120121
[System.IO.FileInfo] $SourceCache = "S:\SourceCache",
121122
[System.IO.FileInfo] $BinaryCache = "S:\b",
122123
[System.IO.FileInfo] $ImageRoot = "S:",
123-
[ValidateSet("codeview", "dwarf")]
124-
[string] $CDebugFormat = "dwarf",
125-
[ValidateSet("codeview", "dwarf")]
126-
[string] $SwiftDebugFormat = "dwarf",
127-
[ValidateRange(1, 36)]
128-
[int] $AndroidAPILevel = 28,
129-
[string[]] $AndroidSDKVersions = @("Android", "AndroidExperimental"),
130-
[string[]] $AndroidSDKArchitectures = @("aarch64", "armv7", "i686", "x86_64"),
131-
[string[]] $WindowsSDKVersions = @("Windows", "WindowsExperimental"),
132-
[string[]] $WindowsSDKArchitectures = @("X64","X86","Arm64"),
133-
[string] $ProductVersion = "0.0.0",
134-
[string] $ToolchainIdentifier = $(if ($env:TOOLCHAIN_VERSION) { $env:TOOLCHAIN_VERSION } else { "$env:USERNAME.development" }),
124+
[string] $Stage = "",
125+
126+
# (Pinned) Bootstrap Toolchain
135127
[string] $PinnedBuild = "",
136128
[ValidatePattern("^([A-Fa-f0-9]{64}|)$")]
137129
[string] $PinnedSHA256 = "",
138130
[string] $PinnedVersion = "",
131+
132+
# Build Caching
133+
[switch] $EnableCaching,
134+
[ValidatePattern('^\d+(\.\d+)*$')]
135+
[string] $SCCacheVersion = "0.10.0",
136+
137+
# SBoM Support
138+
[switch] $IncludeSBoM = $false,
139+
[string] $SyftVersion = "1.29.1",
140+
141+
# Dependencies
139142
[ValidatePattern('^\d+(\.\d+)*$')]
140143
[string] $PythonVersion = "3.9.10",
144+
145+
# Toolchain Version Info
146+
[string] $ProductVersion = "0.0.0",
147+
[string] $ToolchainIdentifier = $(if ($env:TOOLCHAIN_VERSION) { $env:TOOLCHAIN_VERSION } else { "$env:USERNAME.development" }),
148+
149+
# Toolchain Cross-compilation
150+
[ValidateSet("AMD64", "ARM64")]
151+
[string] $HostArchName = $(if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }),
152+
153+
# Debug Information
154+
[switch] $DebugInfo,
155+
[ValidateSet("codeview", "dwarf")]
156+
[string] $CDebugFormat = "dwarf",
157+
[ValidateSet("codeview", "dwarf")]
158+
[string] $SwiftDebugFormat = "dwarf",
159+
160+
# Android SDK Options
161+
[switch] $Android = $false,
141162
[ValidatePattern("^r(?:[1-9]|[1-9][0-9])(?:[a-z])?$")]
142163
[string] $AndroidNDKVersion = "r27c",
164+
[ValidateRange(1, 36)]
165+
[int] $AndroidAPILevel = 28,
166+
[string[]] $AndroidSDKVersions = @("Android", "AndroidExperimental"),
167+
[string[]] $AndroidSDKArchitectures = @("aarch64", "armv7", "i686", "x86_64"),
168+
169+
# Windows SDK Options
143170
[ValidatePattern("^\d+\.\d+\.\d+(?:-\w+)?")]
144171
[string] $WinSDKVersion = "",
145-
[switch] $Android = $false,
172+
[string[]] $WindowsSDKVersions = @("Windows", "WindowsExperimental"),
173+
[string[]] $WindowsSDKArchitectures = @("X64","X86","Arm64"),
174+
175+
# Incremental Build Support
176+
[switch] $Clean,
146177
[switch] $SkipBuild = $false,
147178
[switch] $SkipPackaging = $false,
148-
[switch] $IncludeDS2 = $false,
149-
[switch] $IncludeSBoM = $false,
150179
[string[]] $Test = @(),
151-
[string] $Stage = "",
152-
[ValidateSet("AMD64", "ARM64")]
153-
[string] $HostArchName = $(if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }),
180+
181+
[switch] $IncludeDS2 = $false,
154182
[switch] $IncludeNoAsserts = $false,
155-
[switch] $Clean,
156-
[switch] $DebugInfo,
157-
[ValidatePattern('^\d+(\.\d+)*$')]
158-
[string] $SCCacheVersion = "0.10.0",
159-
[string] $SyftVersion = "1.29.1",
160-
[switch] $EnableCaching,
161183
[ValidateSet("debug", "release")]
162184
[string] $FoundationTestConfiguration = "debug",
185+
163186
[switch] $Summary,
164187
[switch] $ToBatch
165188
)

0 commit comments

Comments
 (0)