Skip to content

Commit 20202f5

Browse files
committed
[CS] Quick workaround for rdar://160135085
Temporarily disable the checking requirements for typealias types, and desugar the typealias since the constraint system does not currently correctly handle type variables in the underlying type.
1 parent 90a5a0f commit 20202f5

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

lib/Sema/TypeOfReference.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,7 @@ class InferableTypeOpener final {
268268
auto substTy = TypeAliasType::get(
269269
aliasTy->getDecl(), transform(aliasTy->getParent()), genericArgs,
270270
transform(aliasTy->getSinglyDesugaredType()));
271-
openGenericTypeRequirements(substTy->getDecl(),
272-
substTy->getSubstitutionMap());
273-
return substTy;
271+
return substTy->getSinglyDesugaredType();
274272
}
275273

276274
Type transformErrorType(ErrorType *errTy) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %empty-directory(%t/modules)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/modules/A.swiftmodule -module-name A %t/a.swift
5+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/modules/B.swiftmodule -module-name B -I %t/modules %t/b.swift
6+
// RUN: %target-swift-frontend -typecheck -I %t/modules %t/c.swift
7+
8+
//--- a.swift
9+
10+
public struct S<T> {
11+
public init(_ x: T) {}
12+
}
13+
14+
//--- b.swift
15+
16+
import A
17+
public typealias S = A.S
18+
19+
//--- c.swift
20+
21+
import A
22+
import B
23+
24+
_ = S(0)

test/Constraints/requirement_opening.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-typecheck-verify-swift
2+
// REQUIRES: rdar160135085
23

34
struct K<U> {} // expected-note 6{{'U' declared as parameter to type 'K'}}
45
protocol Q {}

test/decl/typealias/generic.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,19 @@ func testSugar(_ gx: GX<Int>, _ gy: GX<Int>.GY<Double>, gz: GX<Int>.GY<Double>.E
465465
let i2: Int = gy // expected-error{{cannot convert value of type 'GX<Int>.GY<Double>' (aka 'Array<Double>') to specified type 'Int'}}
466466
let i3: Int = gz // expected-error{{cannot convert value of type 'GX<Int>.GY<Double>.Element' (aka 'Double') to specified type 'Int'}}
467467
}
468+
469+
func testLocalRequirementInference<T>(_ x: T, y: Int, s: S) {
470+
typealias X<U: P> = (T, U) where T == U.A
471+
func foo<V>(_ x: X<V>) {} // expected-note {{where 'V' = 'Int'}} expected-note {{where 'T' = 'T', 'V.A' = 'S.A' (aka 'Float')}}
472+
foo((x, y)) // expected-error {{local function 'foo' requires that 'Int' conform to 'P'}}
473+
foo((x, s)) // expected-error {{local function 'foo' requires the types 'T' and 'S.A' (aka 'Float') be equivalent}}
474+
}
475+
476+
struct TestNestedRequirementInference<T> {
477+
typealias X<U: P> = (T, U) where T == U.A
478+
func foo<V>(_ x: X<V>) {} // expected-note {{where 'V' = 'Int'}} expected-note {{where 'T' = 'T', 'V.A' = 'S.A' (aka 'Float')}}
479+
func bar(_ x: T, y: Int, s: S) {
480+
foo((x, y)) // expected-error {{instance method 'foo' requires that 'Int' conform to 'P'}}
481+
foo((x, s)) // expected-error {{instance method 'foo' requires the types 'T' and 'S.A' (aka 'Float') be equivalent}}
482+
}
483+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// {"kind":"typecheck","signature":"swift::constraints::ConstraintSystem::openGenericParameters(swift::DeclContext*, swift::GenericSignature, llvm::SmallVectorImpl<std::__1::pair<swift::GenericTypeParamType*, swift::TypeVariableType*>>&, swift::constraints::ConstraintLocatorBuilder, swift::constraints::PreparedOverloadBuilder*)","signatureAssert":"Assertion failed: (sig), function openGenericParameters"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
class a<b
4+
func c -> d
5+
typealias c : a
6+
c
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// {"kind":"typecheck","original":"0df5dc82","signature":"swift::constraints::ConstraintSystem::typeVarOccursInType(swift::TypeVariableType*, swift::Type, bool*)","signatureAssert":"Assertion failed: ((!typeVariables.empty() || hasError()) && \"Did not find type variables!\"), function getTypeVariables"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
struct a<each b {
4+
typealias d<c> = (
5+
> func 1 {
6+
typealias e = f
7+
e
8+
typealias e = d

0 commit comments

Comments
 (0)