Skip to content

Commit b6c2b3e

Browse files
committed
[Diagnostics] Fix out-of-bounds index while fixing argument mismatch
Although the overload choice has two parameters, it doesn't mean that there are exactly two arguments passed to it. Resolves: rdar://87407899
1 parent 7f2bde2 commit b6c2b3e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,12 @@ static bool repairOutOfOrderArgumentsInBinaryFunction(
42584258

42594259
auto currArgIdx =
42604260
locator->castLastElementTo<LocatorPathElt::ApplyArgToParam>().getArgIdx();
4261+
4262+
// Argument is extraneous and has been re-ordered to match one
4263+
// of two parameter types.
4264+
if (currArgIdx >= 2)
4265+
return false;
4266+
42614267
auto otherArgIdx = currArgIdx == 0 ? 1 : 0;
42624268

42634269
auto argType = cs.getType(argument);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
2+
// REQUIRES: objc_interop
3+
// REQUIRES: OS=macosx
4+
5+
import SwiftUI
6+
7+
struct AStruct {
8+
let aField: MyEnum = .aCase // expected-note {{change 'let' to 'var' to make it mutable}}
9+
}
10+
11+
enum MyEnum {
12+
case aCase
13+
}
14+
15+
extension EmptyView {
16+
func doImport(showImport: Binding<Bool>, anEnum: MyEnum) -> some View {
17+
EmptyView()
18+
}
19+
}
20+
21+
struct SegFaultingView: View {
22+
@Binding var aStruct: AStruct
23+
@Binding var showImport: Bool
24+
@State var importMessage: String = "none"
25+
26+
var body: some View {
27+
EmptyView()
28+
.doImport(showImport: showImport, // expected-error {{cannot convert value 'showImport' of type 'Bool' to expected type 'Binding<Bool>', use wrapper instead}}
29+
importMessage: importMessage, // expected-error {{extra argument 'importMessage' in call}}
30+
anEnum: $aStruct.aField) // expected-error {{cannot convert value of type 'Binding<MyEnum>' to expected argument type 'MyEnum'}}
31+
// expected-error@-1 {{cannot assign to property: 'aField' is a 'let' constant}}
32+
}
33+
}

0 commit comments

Comments
 (0)