Skip to content

Commit 9eb7ff9

Browse files
committed
[CSStep] Add a nullptr check to IsDeclRefinementOfRequest::evaluate
Interface type of an archetype is not always represented by a `SubstitutableType`, it could be a `DependentMemberType` as well. The code in `IsDeclRefinementOfRequest::evaluate` already partially accounts for that by using `getAs` but the nullptr check is missing which means that the resulting substitution map is incorrect.
1 parent 68a1064 commit 9eb7ff9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Sema/CSStep.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ bool IsDeclRefinementOfRequest::evaluate(Evaluator &evaluator,
650650
auto interfaceTy =
651651
origType->getInterfaceType()->getCanonicalType()->getAs<SubstitutableType>();
652652

653+
if (!interfaceTy)
654+
return CanType();
655+
653656
// Make sure any duplicate bindings are equal to the one already recorded.
654657
// Otherwise, the substitution has conflicting generic arguments.
655658
auto bound = substMap.find(interfaceTy);

test/Sema/diag_ambiguous_overloads.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,29 @@ do {
163163

164164
f2(f1) // expected-error {{no 'f1' candidates produce the expected type '(String) -> Void' for parameter #0}}
165165
}
166+
167+
// https://forums.swift.org/t/1-x-type-inference/69417/15
168+
protocol N { associatedtype D }
169+
170+
infix operator ++ : AdditionPrecedence
171+
infix operator -- : AdditionPrecedence
172+
173+
func ++ <T: N> (lhs: T, rhs: T) -> T.D { fatalError() } // expected-note {{found this candidate}}
174+
func ++ <T: N> (lhs: T, rhs: T) -> T { fatalError() } // expected-note {{found this candidate}}
175+
176+
func -- <T: N> (lhs: T, rhs: T) -> T { fatalError() } // expected-note {{found this candidate}}
177+
func -- <T: N> (lhs: T, rhs: T) -> T.D { fatalError() } // expected-note {{found this candidate}}
178+
179+
do {
180+
struct MyInt16: N { typealias D = MyInt32 }
181+
struct MyInt32: N { typealias D = MyInt64 }
182+
struct MyInt64 {}
183+
184+
var i16 = MyInt16()
185+
186+
let _ = i16 ++ i16
187+
// expected-error@-1 {{ambiguous use of operator '++'}}
188+
189+
let _ = i16 -- i16
190+
// expected-error@-1 {{ambiguous use of operator '--'}}
191+
}

0 commit comments

Comments
 (0)