Skip to content

Commit 6e938f8

Browse files
authored
Merge pull request #20402 from rudkx/fix-default-literal-type-bug
[ConstraintSystem] Fix crash due to not all literal protocols having …
2 parents 094b749 + ffcbe70 commit 6e938f8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,9 @@ void ConstraintSystem::sortDesignatedTypes(
17501750

17511751
for (auto *protocol : argInfo.getLiteralProtocols()) {
17521752
auto defaultType = TC.getDefaultType(protocol, DC);
1753+
// ExpressibleByNilLiteral does not have a default type.
1754+
if (!defaultType)
1755+
continue;
17531756
auto *nominal = defaultType->getAnyNominal();
17541757
for (size_t i = nextType + 1; i < nominalTypes.size(); ++i) {
17551758
if (nominal == nominalTypes[i]) {

test/Constraints/add_with_nil.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 5 -solver-enable-operator-designated-types -solver-disable-shrink -disable-constraint-solver-performance-hacks
2+
3+
func test(_ x: Int) -> Int {
4+
return x + nil
5+
// expected-error@-1 {{cannot convert value of type 'Int' to expected argument type '_.Stride'}}
6+
}

0 commit comments

Comments
 (0)