Skip to content

[CSSimplify] When trying to simplify bind with error type fail gracefully #16866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,16 @@ ConstraintSystem::matchTypesBindTypeVar(
if (!isBindable(typeVar, type))
return formUnsolvedResult();

// Since member lookup doesn't check requirements
// it might sometimes return types which are not
// visible in the current context e.g. typealias
// defined in constrained extension, substitution
// of which might produce error type for base, so
// assignement should thead lightly and just fail
// if it encounters such types.
if (type->hasError())
return getTypeMatchFailure(locator);

// Equal constraints allow mixed LValue/RValue bindings, but
// if we bind a type to a type variable that can bind to
// LValues as part of simplifying the Equal constraint we may
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: not --crash %target-swift-frontend -typecheck %s
// REQUIRES: asserts
// RUN: not %target-swift-frontend -typecheck %s


protocol A {
associatedtype B
Expand Down
39 changes: 39 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0159-rdar39931339.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %target-typecheck-verify-swift

protocol P0 {
associatedtype A
}

protocol P1 {
associatedtype B : P3 = S0<S2>
associatedtype C = ()
}

protocol P2 {
associatedtype D : P1
associatedtype E : P3 = S0<S2>
}

protocol P3 : P0 where A : P2 {}

struct S0<T> : P0 {
typealias A = T
}

extension S0 : P3 where T : P2 {}

struct S2 : P2 {
struct D : P1 {
let value: S2
}
}

extension P1 where C : P2 {
typealias B = C.E
}

extension P3 {
func foo() {
_ = A.D.B.self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// REQUIRES: asserts
// RUN: not --crash %target-swift-frontend %s -emit-ir

// RUN: not %target-swift-frontend %s -emit-ir
protocol A{{}protocol a{extension{class a<a{let d=a(class a<P
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
class a<a{class a{extension{protocol P{class a:a{func a:Self.a