Skip to content

Commit 7f9d364

Browse files
committed
Parse: Fix crash in error recovery path with specifier before parameter name
We should let Sema set ParamDecl's specifier always, instead of setting it in the parser in this odd corner case where we're recovering from 'inout' being written before the parameter name.
1 parent c968a20 commit 7f9d364

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/Parse/ParsePattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ mapParsedParameters(Parser &parser,
425425
Identifier argName, SourceLoc argNameLoc,
426426
Identifier paramName, SourceLoc paramNameLoc)
427427
-> ParamDecl * {
428-
auto param = new (ctx) ParamDecl(paramInfo.SpecifierKind,
428+
auto param = new (ctx) ParamDecl(VarDecl::Specifier::Default,
429429
paramInfo.SpecifierLoc,
430430
argNameLoc, argName,
431431
paramNameLoc, paramName, Type(),

test/decl/subscript/subscripting.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,8 @@ struct InOutSubscripts {
381381

382382
subscript(x3: (inout Int) -> ()) -> Int { return 0 } // ok
383383
subscript(x4: (inout Int, inout Int) -> ()) -> Int { return 0 } // ok
384+
385+
subscript(inout x5: Int) -> Int { return 0 }
386+
// expected-error@-1 {{'inout' before a parameter name is not allowed, place it before the parameter type instead}}
387+
// expected-error@-2 {{'inout' must not be used on subscript parameters}}
384388
}

0 commit comments

Comments
 (0)