Skip to content

[Sema] SE-0213: Fix LinkedExprAnalyzer to not record types for lite… #18384

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
Jul 31, 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
9 changes: 6 additions & 3 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,12 @@ namespace {

// Coercion exprs have a rigid type, so there's no use in gathering info
// about them.
if (isa<CoerceExpr>(expr)) {
LTI.collectedTypes.insert(CS.getType(expr).getPointer());

if (auto *coercion = dyn_cast<CoerceExpr>(expr)) {
// Let's not collect information about types initialized by
// coercions just like we don't for regular initializer calls,
// because that might lead to overly eager type variable merging.
if (!coercion->isLiteralInit())
LTI.collectedTypes.insert(CS.getType(expr).getPointer());
return { false, expr };
}

Expand Down
74 changes: 74 additions & 0 deletions test/Constraints/rdar42750089.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// RUN: %target-typecheck-verify-swift

protocol P : Equatable {
associatedtype T = String
}

struct S : Hashable {
var key: String

init(_ key: String) {
self.key = key
}
}

extension S : ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
self.init(value)
}
}

extension S : _ExpressibleByStringInterpolation {
init(stringInterpolation strings: S...) {
self.key = "foo"
}

init<T>(stringInterpolationSegment expr: T) {
self.init(String(describing: expr))
}
}

extension S : P {}

struct ConcP<F: P, S: P> : P where F.T == S.T {
var lhs: F
var rhs: S
}

struct Z : P {
}

extension P {
func bar() -> Z { fatalError() }

static func +<T : P>(lhs: Self, rhs: T) -> ConcP<Self, T> {
return ConcP(lhs: lhs, rhs: rhs)
}
}

class Container<V> {
var value: V
init(_ value: V) {
self.value = value
}
}

struct A {
enum Value : CustomStringConvertible {
case foo, bar

var description: String {
switch self {
case .foo: return "foo"
case .bar: return "bar"
}
}
}

var value: Container<Value>

func foo() {
let value = self.value.value
_ = S("A") + S("\(value)").bar() + S("B") // Ok
}
}