Skip to content

Commit ffedc8a

Browse files
authored
Merge pull request #17723 from slavapestov/tests-and-cleanup
Tests and cleanup
2 parents 2a3d658 + 308463a commit ffedc8a

23 files changed

+101
-121
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,6 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
376376
if (inheritedTy->hasError())
377377
continue;
378378

379-
// Retrieve the interface type for this inherited type.
380-
//
381-
// If we have a generic parameter, mapTypeOutOfContext() might not
382-
// work yet, if we're calling this while building the generic
383-
// signature. However, we're also not storing inheritedTy back
384-
// anywhere, so it's OK to leave it as an archetype.
385-
//
386-
// FIXME: Ideally, we wouldn't have code paths that take a mix
387-
// of archetypes and interface types. Other than generic parameters,
388-
// the only time we get an interface type here is with invalid
389-
// circular cases. That should be diagnosed elsewhere.
390-
if (inheritedTy->hasArchetype() && !isa<GenericTypeParamDecl>(decl))
391-
inheritedTy = inheritedTy->mapTypeOutOfContext();
392-
393379
// Check whether we inherited from the same type twice.
394380
CanType inheritedCanTy = inheritedTy->getCanonicalType();
395381
auto knownType = inheritedTypes.find(inheritedCanTy);

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -944,22 +944,6 @@ static Type diagnoseUnknownType(TypeChecker &tc, DeclContext *dc,
944944
tc.diagnose(comp->getIdLoc(), diag::no_module_type,
945945
comp->getIdentifier(), moduleType->getModule()->getName());
946946
} else {
947-
// Situation where class tries to inherit from itself, such
948-
// would produce an assertion when trying to lookup members of the class.
949-
//
950-
// FIXME: Handle this in a more principled way, since there are many
951-
// similar checks.
952-
if (auto superClass = parentType->getSuperclass()) {
953-
if (superClass->isEqual(parentType)) {
954-
auto decl = parentType->getAnyNominal();
955-
if (decl) {
956-
tc.diagnose(decl->getLoc(), diag::circular_class_inheritance,
957-
decl->getName());
958-
return ErrorType::get(tc.Context);
959-
}
960-
}
961-
}
962-
963947
LookupResult memberLookup;
964948
// Let's try to lookup given identifier as a member of the parent type,
965949
// this allows for more precise diagnostic, which distinguishes between

test/attr/attr_dynamic_infer.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
// RUN: %target-swift-ide-test -print-ast-typechecked -source-filename=%s -print-implicit-attrs -disable-objc-attr-requires-foundation-module -swift-version 3 | %FileCheck %s
1+
// RUN: %target-swift-ide-test -print-ast-typechecked -source-filename=%s -print-implicit-attrs -disable-objc-attr-requires-foundation-module | %FileCheck %s
22

33
@objc class Super {
4-
func baseFoo() {}
4+
@objc dynamic func baseFoo() {}
55
}
66

77
// CHECK: extension Super {
88
extension Super {
99
// CHECK: @objc dynamic func foo
10-
func foo() { }
10+
@objc func foo() { }
1111

1212
// CHECK: @objc dynamic var prop: Super
13-
var prop: Super {
13+
@objc var prop: Super {
1414
// CHECK: @objc dynamic get
1515
get { return Super() }
1616
// CHECK: @objc dynamic set
1717
set { }
1818
}
1919

2020
// CHECK: @objc dynamic subscript(sup: Super) -> Super
21-
subscript(sup: Super) -> Super {
21+
@objc subscript(sup: Super) -> Super {
2222
// CHECK: @objc dynamic get
2323
get { return sup }
2424
// CHECK: @objc dynamic set
@@ -60,28 +60,28 @@ extension Sub {
6060

6161
extension FinalTests {
6262
// CHECK: @objc final func foo
63-
final func foo() { }
63+
@objc final func foo() { }
6464

6565
// CHECK: @objc final var prop: Super
66-
final var prop: Super {
66+
@objc final var prop: Super {
6767
// CHECK: @objc final get
6868
get { return Super() }
6969
// CHECK: @objc final set
7070
set { }
7171
}
7272

7373
// CHECK: @objc final subscript(sup: Super) -> Super
74-
final subscript(sup: Super) -> Super {
74+
@objc final subscript(sup: Super) -> Super {
7575
// CHECK: @objc final get
7676
get { return sup }
7777
// CHECK: @objc final set
7878
set { }
7979
}
8080

8181
// CHECK: @objc static var x
82-
static var x: Int = 0
82+
@objc static var x: Int = 0
8383

8484
// CHECK: @objc static func bar
85-
static func bar() { }
85+
@objc static func bar() { }
8686
}
8787

test/decl/class/override.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -parse-as-library -enable-objc-interop -swift-version 3
1+
// RUN: %target-typecheck-verify-swift -parse-as-library -enable-objc-interop
22

33
class A {
44
func ret_sametype() -> Int { return 0 }
@@ -161,23 +161,23 @@ class H : G {
161161
}
162162

163163
@objc class IUOTestBaseClass {
164-
func none() {}
164+
@objc func none() {}
165165

166-
func oneA(_: AnyObject) {}
167-
func oneB(x: AnyObject) {}
168-
func oneC(_ x: AnyObject) {}
166+
@objc func oneA(_: AnyObject) {}
167+
@objc func oneB(x: AnyObject) {}
168+
@objc func oneC(_ x: AnyObject) {}
169169

170-
func manyA(_: AnyObject, _: AnyObject) {}
171-
func manyB(_ a: AnyObject, b: AnyObject) {}
172-
func manyC(var a: AnyObject, // expected-error {{'var' as a parameter attribute is not allowed}}
173-
var b: AnyObject) {} // expected-error {{'var' as a parameter attribute is not allowed}}
170+
@objc func manyA(_: AnyObject, _: AnyObject) {}
171+
@objc func manyB(_ a: AnyObject, b: AnyObject) {}
172+
@objc func manyC(var a: AnyObject, // expected-error {{'var' as a parameter attribute is not allowed}}
173+
var b: AnyObject) {} // expected-error {{'var' as a parameter attribute is not allowed}}
174174

175-
func result() -> AnyObject? { return nil }
176-
func both(_ x: AnyObject) -> AnyObject? { return x }
175+
@objc func result() -> AnyObject? { return nil }
176+
@objc func both(_ x: AnyObject) -> AnyObject? { return x }
177177

178-
init(_: AnyObject) {}
179-
init(one: AnyObject) {}
180-
init(a: AnyObject, b: AnyObject) {}
178+
@objc init(_: AnyObject) {}
179+
@objc init(one: AnyObject) {}
180+
@objc init(a: AnyObject, b: AnyObject) {}
181181
}
182182

183183
class IUOTestSubclass : IUOTestBaseClass {

test/decl/nested/type_in_function.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ struct OuterGenericStruct<A> {
128128
func genericFunction<T>(t: T) {
129129
class First : Second<T>.UnknownType { }
130130
// expected-error@-1 {{type 'First' cannot be nested in generic function 'genericFunction(t:)'}}
131+
// expected-error@-2 {{'UnknownType' is not a member type of 'Second<T>'}}
131132
class Second<T> : Second { }
132133
// expected-error@-1 {{type 'Second' cannot be nested in generic function 'genericFunction(t:)'}}
133-
// expected-error@-2 2 {{'Second' inherits from itself}}
134+
// expected-error@-2 {{'Second' inherits from itself}}
134135
}
135136

136137
// Spurious "Self or associated type requirements" diagnostic.

validation-test/Sema/type_checker_crashers_fixed/rdar27261929.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
// RUN: %target-swift-frontend %s -typecheck -swift-version 3
1+
// RUN: %target-swift-frontend %s -typecheck -verify
2+
3+
// Note: this used to type check successfully in Swift 3. In Swift 4, it produces
4+
// an error, so probably this test isn't testing anything useful anymore, since
5+
// we already exercise many such cases in test/Constraints/tuple_arguments.swift.
6+
// However, there's no harm in keeping it around in case it exposes other bugs later.
27

38
public enum R<V> {
49
case value(V)
@@ -14,7 +19,7 @@ public struct P<I, O> {
1419
public func test() -> P<I, [O]> {
1520
return P<I, [O]> { input in
1621
var output: [O] = []
17-
_ = R<([O], I)>.value(output, input)
22+
_ = R<([O], I)>.value(output, input) // expected-error {{enum element 'value' expects a single parameter of type '([O], I)'}}
1823
return R<([O], I)>.value((output, input))
1924
}
2025
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
1+
// RUN: %target-swift-frontend %s -emit-silgen
22

33
// rdar://problem/19792730
44

55
public func foo<
66
Expected : Sequence,
77
Actual : Sequence,
88
T : Comparable
9+
>(expected: Expected, actual: Actual)
910
where
1011
Expected.Iterator.Element == Actual.Iterator.Element,
11-
Expected.Iterator.Element == T
12-
>(expected: Expected, actual: Actual) {}
12+
Expected.Iterator.Element == T {}
1313

1414
public func foo<
1515
Expected : Sequence,
1616
Actual : Sequence,
1717
T : Comparable
18+
>(expected: Expected, actual: Actual)
1819
where
1920
Expected.Iterator.Element == Actual.Iterator.Element,
20-
Expected.Iterator.Element == (T, T)
21-
>(expected: Expected, actual: Actual) {}
21+
Expected.Iterator.Element == (T, T) {}
2222

validation-test/compiler_crashers_2_fixed/0002-rdar19792768.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
1+
// RUN: %target-swift-frontend %s -emit-silgen
22

33
// rdar://problem/19792768
44

55
public func foo<
66
Expected : Sequence,
77
Actual : Sequence,
88
T : Comparable
9+
>(_ expected: Expected, _ actual: Actual)
910
where
1011
Expected.Iterator.Element == Actual.Iterator.Element,
11-
Expected.Iterator.Element == (T, T)
12-
>(_ expected: Expected, _ actual: Actual) {}
12+
Expected.Iterator.Element == (T, T) {}
1313

1414
func f() {
1515
foo(

validation-test/compiler_crashers_2_fixed/0012-rdar20270240.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
1+
// RUN: %target-swift-frontend %s -emit-silgen
22

33
protocol FooProtocol {
44
associatedtype Element
@@ -10,9 +10,9 @@ protocol Bar {
1010

1111
mutating func extend<
1212
C : FooProtocol
13+
>(elements: C)
1314
where
1415
C.Element == Element
15-
>(elements: C)
1616
}
1717

1818
struct FooImpl<T> : FooProtocol {
@@ -27,8 +27,8 @@ struct BarImpl<T> : Bar {
2727

2828
mutating func extend<
2929
C : FooProtocol
30+
>(elements: C)
3031
where
31-
C.Element == T
32-
>(elements: C) {}
32+
C.Element == T {}
3333
}
3434

validation-test/compiler_crashers_2_fixed/0013-rdar19519590.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -swift-version 3
1+
// RUN: %target-swift-frontend %s -emit-ir
22

33
protocol SourceTargetTransformable {
44
associatedtype Source
@@ -15,13 +15,13 @@ struct PiecewiseTransformedIteratorOf<
1515
SourceIterator: IteratorProtocol,
1616
TransformerIterator: IteratorProtocol,
1717
Transformable: SourceTargetTransformable
18-
where
19-
Transformable.Source == Source,
20-
Transformable.Target == Target,
21-
SourceIterator.Element == Source,
22-
TransformerIterator.Element == Transformable.Transformer
2318
>
24-
: IteratorProtocol {
19+
: IteratorProtocol
20+
where
21+
Transformable.Source == Source,
22+
Transformable.Target == Target,
23+
SourceIterator.Element == Source,
24+
TransformerIterator.Element == Transformable.Transformer {
2525
typealias Element = Target
2626

2727
var sourceIterator: SourceIterator
@@ -46,10 +46,10 @@ struct PiecewiseTransformedSequenceOf<
4646
SourceSequence: Sequence,
4747
TransformerSequence: Sequence,
4848
Transformable: SourceTargetTransformable
49+
>: Sequence
4950
where
5051
SourceSequence.Iterator.Element == Transformable.Source,
51-
TransformerSequence.Iterator.Element == Transformable.Transformer
52-
>: Sequence {
52+
TransformerSequence.Iterator.Element == Transformable.Transformer {
5353

5454
typealias Source = SourceSequence.Iterator.Element
5555
typealias Target = Transformable.Target

validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
1+
// RUN: %target-swift-frontend %s -emit-silgen
22

33
import StdlibUnittest
44

@@ -389,15 +389,16 @@ public struct LoggingCollection<Base_ : MyCollection> : LoggingCollectionType {
389389
}
390390

391391
public func expectCustomizable<
392-
T : Wrapper where
393-
T : LoggingType,
394-
T.Base : Wrapper, T.Base : LoggingType,
395-
T.Log == T.Base.Log
392+
T : Wrapper
396393
>(_: T, _ counters: TypeIndexed<Int>,
397394
stackTrace: SourceLocStack? = nil,
398395
file: String = #file, line: UInt = #line,
399396
collectMoreInfo: (()->String)? = nil
400-
) {
397+
)
398+
where
399+
T : LoggingType,
400+
T.Base : Wrapper, T.Base : LoggingType,
401+
T.Log == T.Base.Log {
401402
expectNotEqual(
402403
0, counters[T.self], collectMoreInfo?() ?? "",
403404
stackTrace: stackTrace ?? SourceLocStack(), file: file, line: line)
@@ -408,15 +409,16 @@ public func expectCustomizable<
408409
}
409410

410411
public func expectNotCustomizable<
411-
T : Wrapper where
412-
T : LoggingType,
413-
T.Base : Wrapper, T.Base : LoggingType,
414-
T.Log == T.Base.Log
412+
T : Wrapper
415413
>(_: T, _ counters: TypeIndexed<Int>,
416414
stackTrace: SourceLocStack? = nil,
417415
file: String = #file, line: UInt = #line,
418416
collectMoreInfo: (()->String)? = nil
419-
) {
417+
)
418+
where
419+
T : LoggingType,
420+
T.Base : Wrapper, T.Base : LoggingType,
421+
T.Log == T.Base.Log {
420422
expectNotEqual(
421423
0, counters[T.self], collectMoreInfo?() ?? "",
422424
stackTrace: stackTrace ?? SourceLocStack(), file: file, line: line)

validation-test/compiler_crashers_2_fixed/0053-sr490.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -swift-version 3
1+
// RUN: %target-swift-frontend %s -emit-ir
22

33
enum Value {
44
case IntValue(Int)
@@ -13,7 +13,7 @@ protocol Storable {
1313

1414
protocol RawProducable {
1515
var rawValueForType : Int16 { get }
16-
init<T: Storable where T.Representation == Self>(value: T)
16+
init<T: Storable>(value: T) where T.Representation == Self
1717
}
1818

1919
extension Int : Storable {

validation-test/compiler_crashers_2_fixed/0060-sr2702.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -swift-version 3
2-
// RUN: %target-swift-frontend %s -emit-ir -O -swift-version 3
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
// RUN: %target-swift-frontend %s -emit-ir -O
33

44
// REQUIRES: objc_interop
55

@@ -47,16 +47,14 @@ public func XUAllSubclassesOfClass<T: AnyObject>(_ aClass: T.Type) -> [T.Type] {
4747
}
4848

4949
let classesPtr = memory.assumingMemoryBound(to: Optional<AnyClass>.self)
50-
let classes = AutoreleasingUnsafeMutablePointer<AnyClass?>(classesPtr)
50+
let classes = AutoreleasingUnsafeMutablePointer<AnyClass>(classesPtr)
5151
numClasses = objc_getClassList(classes, numClasses)
5252

5353
for i in 0 ..< Int(numClasses) {
5454
// Go through the classes, find out if the class is kind of aClass
5555
// and then add it to the list
5656

57-
guard let cl = classes[i] else {
58-
continue
59-
}
57+
let cl = classes[i]
6058

6159
if XUClassKindOfClass(cl, wantedSuperclass: aClass) && cl != aClass {
6260
result.append(cl as! T.Type)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend %s -emit-ir
2+
3+
protocol P {}
4+
5+
class Base<T: P> {}
6+
7+
class Derived: Base<Derived>, P {}

0 commit comments

Comments
 (0)