Skip to content

Commit b12537f

Browse files
authored
Merge pull request #65667 from tshortli/swiftinterface-missing-conformance-req-assert
Sema: Fix incorrect assert in TypeCheckProtocol.cpp.
2 parents 0a55811 + ba422f9 commit b12537f

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,11 +1504,12 @@ bool WitnessChecker::findBestWitness(
15041504
if (SF->Kind == SourceFileKind::Interface) {
15051505
auto match = matchWitness(ReqEnvironmentCache, Proto,
15061506
conformance, DC, requirement, requirement);
1507-
assert(match.isViable());
1508-
numViable = 1;
1509-
bestIdx = matches.size();
1510-
matches.push_back(std::move(match));
1511-
return true;
1507+
if (match.isViable()) {
1508+
numViable = 1;
1509+
bestIdx = matches.size();
1510+
matches.push_back(std::move(match));
1511+
return true;
1512+
}
15121513
}
15131514
}
15141515
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-compiler-version: Swift version 5.0
3+
// swift-module-flags:
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: not %target-swift-frontend -typecheck-module-from-interface -module-name Broken %s 2>%t/interface-verification-errors.txt
7+
// RUN: %FileCheck %s < %t/interface-verification-errors.txt
8+
9+
import Swift
10+
11+
// This type is meant to shadow the name of the module, creating an ambiguity.
12+
public struct Broken {}
13+
14+
public struct BrokenOptions : Swift.OptionSet {
15+
public let rawValue: Swift.Int
16+
public static let none: Broken.BrokenOptions
17+
public static let anOption: Broken.BrokenOptions
18+
public init(rawValue: Swift.Int)
19+
public typealias ArrayLiteralElement = Broken.BrokenOptions
20+
public typealias Element = Broken.BrokenOptions
21+
public typealias RawValue = Swift.Int
22+
}
23+
24+
// CHECK: error: 'BrokenOptions' is not a member type of struct 'Broken.Broken'
25+
// CHECK: error: 'BrokenOptions' is not a member type of struct 'Broken.Broken'
26+
// CHECK: error: 'BrokenOptions' is not a member type of struct 'Broken.Broken'
27+
// CHECK: error: 'BrokenOptions' is not a member type of struct 'Broken.Broken'
28+
29+
// CHECK: error: type 'BrokenOptions' does not conform to protocol 'OptionSet'
30+
// CHECK: error: type 'BrokenOptions' does not conform to protocol 'SetAlgebra'
31+
// CHECK: note: candidate would match if 'BrokenOptions.Element' was the same type as 'τ_0_0.Element'
32+
// CHECK: error: type 'BrokenOptions' does not conform to protocol 'ExpressibleByArrayLiteral'
33+
// CHECK: note: protocol requires nested type 'Element'; do you want to add it?
34+
// CHECK: note: protocol requires initializer 'init(_:)' with type 'S'
35+
// CHECK: note: protocol requires nested type 'ArrayLiteralElement'; do you want to add it?
36+
// CHECK: error: failed to verify module interface of 'Broken' due to the errors above; the textual interface may be broken by project issues, differences between compilers

0 commit comments

Comments
 (0)