Skip to content

Tests and cleanup #17723

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 6 commits into from
Jul 3, 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
14 changes: 0 additions & 14 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,20 +376,6 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
if (inheritedTy->hasError())
continue;

// Retrieve the interface type for this inherited type.
//
// If we have a generic parameter, mapTypeOutOfContext() might not
// work yet, if we're calling this while building the generic
// signature. However, we're also not storing inheritedTy back
// anywhere, so it's OK to leave it as an archetype.
//
// FIXME: Ideally, we wouldn't have code paths that take a mix
// of archetypes and interface types. Other than generic parameters,
// the only time we get an interface type here is with invalid
// circular cases. That should be diagnosed elsewhere.
if (inheritedTy->hasArchetype() && !isa<GenericTypeParamDecl>(decl))
inheritedTy = inheritedTy->mapTypeOutOfContext();

// Check whether we inherited from the same type twice.
CanType inheritedCanTy = inheritedTy->getCanonicalType();
auto knownType = inheritedTypes.find(inheritedCanTy);
Expand Down
16 changes: 0 additions & 16 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,22 +944,6 @@ static Type diagnoseUnknownType(TypeChecker &tc, DeclContext *dc,
tc.diagnose(comp->getIdLoc(), diag::no_module_type,
comp->getIdentifier(), moduleType->getModule()->getName());
} else {
// Situation where class tries to inherit from itself, such
// would produce an assertion when trying to lookup members of the class.
//
// FIXME: Handle this in a more principled way, since there are many
// similar checks.
if (auto superClass = parentType->getSuperclass()) {
if (superClass->isEqual(parentType)) {
auto decl = parentType->getAnyNominal();
if (decl) {
tc.diagnose(decl->getLoc(), diag::circular_class_inheritance,
decl->getName());
return ErrorType::get(tc.Context);
}
}
}

LookupResult memberLookup;
// Let's try to lookup given identifier as a member of the parent type,
// this allows for more precise diagnostic, which distinguishes between
Expand Down
20 changes: 10 additions & 10 deletions test/attr/attr_dynamic_infer.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// 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
// RUN: %target-swift-ide-test -print-ast-typechecked -source-filename=%s -print-implicit-attrs -disable-objc-attr-requires-foundation-module | %FileCheck %s

@objc class Super {
func baseFoo() {}
@objc dynamic func baseFoo() {}
}

// CHECK: extension Super {
extension Super {
// CHECK: @objc dynamic func foo
func foo() { }
@objc func foo() { }

// CHECK: @objc dynamic var prop: Super
var prop: Super {
@objc var prop: Super {
// CHECK: @objc dynamic get
get { return Super() }
// CHECK: @objc dynamic set
set { }
}

// CHECK: @objc dynamic subscript(sup: Super) -> Super
subscript(sup: Super) -> Super {
@objc subscript(sup: Super) -> Super {
// CHECK: @objc dynamic get
get { return sup }
// CHECK: @objc dynamic set
Expand Down Expand Up @@ -60,28 +60,28 @@ extension Sub {

extension FinalTests {
// CHECK: @objc final func foo
final func foo() { }
@objc final func foo() { }

// CHECK: @objc final var prop: Super
final var prop: Super {
@objc final var prop: Super {
// CHECK: @objc final get
get { return Super() }
// CHECK: @objc final set
set { }
}

// CHECK: @objc final subscript(sup: Super) -> Super
final subscript(sup: Super) -> Super {
@objc final subscript(sup: Super) -> Super {
// CHECK: @objc final get
get { return sup }
// CHECK: @objc final set
set { }
}

// CHECK: @objc static var x
static var x: Int = 0
@objc static var x: Int = 0

// CHECK: @objc static func bar
static func bar() { }
@objc static func bar() { }
}

28 changes: 14 additions & 14 deletions test/decl/class/override.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -parse-as-library -enable-objc-interop -swift-version 3
// RUN: %target-typecheck-verify-swift -parse-as-library -enable-objc-interop

class A {
func ret_sametype() -> Int { return 0 }
Expand Down Expand Up @@ -161,23 +161,23 @@ class H : G {
}

@objc class IUOTestBaseClass {
func none() {}
@objc func none() {}

func oneA(_: AnyObject) {}
func oneB(x: AnyObject) {}
func oneC(_ x: AnyObject) {}
@objc func oneA(_: AnyObject) {}
@objc func oneB(x: AnyObject) {}
@objc func oneC(_ x: AnyObject) {}

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

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

init(_: AnyObject) {}
init(one: AnyObject) {}
init(a: AnyObject, b: AnyObject) {}
@objc init(_: AnyObject) {}
@objc init(one: AnyObject) {}
@objc init(a: AnyObject, b: AnyObject) {}
}

class IUOTestSubclass : IUOTestBaseClass {
Expand Down
3 changes: 2 additions & 1 deletion test/decl/nested/type_in_function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ struct OuterGenericStruct<A> {
func genericFunction<T>(t: T) {
class First : Second<T>.UnknownType { }
// expected-error@-1 {{type 'First' cannot be nested in generic function 'genericFunction(t:)'}}
// expected-error@-2 {{'UnknownType' is not a member type of 'Second<T>'}}
class Second<T> : Second { }
// expected-error@-1 {{type 'Second' cannot be nested in generic function 'genericFunction(t:)'}}
// expected-error@-2 2 {{'Second' inherits from itself}}
// expected-error@-2 {{'Second' inherits from itself}}
}

// Spurious "Self or associated type requirements" diagnostic.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
// RUN: %target-swift-frontend %s -typecheck -swift-version 3
// RUN: %target-swift-frontend %s -typecheck -verify

// Note: this used to type check successfully in Swift 3. In Swift 4, it produces
// an error, so probably this test isn't testing anything useful anymore, since
// we already exercise many such cases in test/Constraints/tuple_arguments.swift.
// However, there's no harm in keeping it around in case it exposes other bugs later.

public enum R<V> {
case value(V)
Expand All @@ -14,7 +19,7 @@ public struct P<I, O> {
public func test() -> P<I, [O]> {
return P<I, [O]> { input in
var output: [O] = []
_ = R<([O], I)>.value(output, input)
_ = R<([O], I)>.value(output, input) // expected-error {{enum element 'value' expects a single parameter of type '([O], I)'}}
return R<([O], I)>.value((output, input))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
// RUN: %target-swift-frontend %s -emit-silgen

// rdar://problem/19792730

public func foo<
Expected : Sequence,
Actual : Sequence,
T : Comparable
>(expected: Expected, actual: Actual)
where
Expected.Iterator.Element == Actual.Iterator.Element,
Expected.Iterator.Element == T
>(expected: Expected, actual: Actual) {}
Expected.Iterator.Element == T {}

public func foo<
Expected : Sequence,
Actual : Sequence,
T : Comparable
>(expected: Expected, actual: Actual)
where
Expected.Iterator.Element == Actual.Iterator.Element,
Expected.Iterator.Element == (T, T)
>(expected: Expected, actual: Actual) {}
Expected.Iterator.Element == (T, T) {}

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
// RUN: %target-swift-frontend %s -emit-silgen

// rdar://problem/19792768

public func foo<
Expected : Sequence,
Actual : Sequence,
T : Comparable
>(_ expected: Expected, _ actual: Actual)
where
Expected.Iterator.Element == Actual.Iterator.Element,
Expected.Iterator.Element == (T, T)
>(_ expected: Expected, _ actual: Actual) {}
Expected.Iterator.Element == (T, T) {}

func f() {
foo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
// RUN: %target-swift-frontend %s -emit-silgen

protocol FooProtocol {
associatedtype Element
Expand All @@ -10,9 +10,9 @@ protocol Bar {

mutating func extend<
C : FooProtocol
>(elements: C)
where
C.Element == Element
>(elements: C)
}

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

mutating func extend<
C : FooProtocol
>(elements: C)
where
C.Element == T
>(elements: C) {}
C.Element == T {}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend %s -emit-ir -swift-version 3
// RUN: %target-swift-frontend %s -emit-ir

protocol SourceTargetTransformable {
associatedtype Source
Expand All @@ -15,13 +15,13 @@ struct PiecewiseTransformedIteratorOf<
SourceIterator: IteratorProtocol,
TransformerIterator: IteratorProtocol,
Transformable: SourceTargetTransformable
where
Transformable.Source == Source,
Transformable.Target == Target,
SourceIterator.Element == Source,
TransformerIterator.Element == Transformable.Transformer
>
: IteratorProtocol {
: IteratorProtocol
where
Transformable.Source == Source,
Transformable.Target == Target,
SourceIterator.Element == Source,
TransformerIterator.Element == Transformable.Transformer {
typealias Element = Target

var sourceIterator: SourceIterator
Expand All @@ -46,10 +46,10 @@ struct PiecewiseTransformedSequenceOf<
SourceSequence: Sequence,
TransformerSequence: Sequence,
Transformable: SourceTargetTransformable
>: Sequence
where
SourceSequence.Iterator.Element == Transformable.Source,
TransformerSequence.Iterator.Element == Transformable.Transformer
>: Sequence {
TransformerSequence.Iterator.Element == Transformable.Transformer {

typealias Source = SourceSequence.Iterator.Element
typealias Target = Transformable.Target
Expand Down
24 changes: 13 additions & 11 deletions validation-test/compiler_crashers_2_fixed/0022-rdar21625478.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend %s -emit-silgen -swift-version 3
// RUN: %target-swift-frontend %s -emit-silgen

import StdlibUnittest

Expand Down Expand Up @@ -389,15 +389,16 @@ public struct LoggingCollection<Base_ : MyCollection> : LoggingCollectionType {
}

public func expectCustomizable<
T : Wrapper where
T : LoggingType,
T.Base : Wrapper, T.Base : LoggingType,
T.Log == T.Base.Log
T : Wrapper
>(_: T, _ counters: TypeIndexed<Int>,
stackTrace: SourceLocStack? = nil,
file: String = #file, line: UInt = #line,
collectMoreInfo: (()->String)? = nil
) {
)
where
T : LoggingType,
T.Base : Wrapper, T.Base : LoggingType,
T.Log == T.Base.Log {
expectNotEqual(
0, counters[T.self], collectMoreInfo?() ?? "",
stackTrace: stackTrace ?? SourceLocStack(), file: file, line: line)
Expand All @@ -408,15 +409,16 @@ public func expectCustomizable<
}

public func expectNotCustomizable<
T : Wrapper where
T : LoggingType,
T.Base : Wrapper, T.Base : LoggingType,
T.Log == T.Base.Log
T : Wrapper
>(_: T, _ counters: TypeIndexed<Int>,
stackTrace: SourceLocStack? = nil,
file: String = #file, line: UInt = #line,
collectMoreInfo: (()->String)? = nil
) {
)
where
T : LoggingType,
T.Base : Wrapper, T.Base : LoggingType,
T.Log == T.Base.Log {
expectNotEqual(
0, counters[T.self], collectMoreInfo?() ?? "",
stackTrace: stackTrace ?? SourceLocStack(), file: file, line: line)
Expand Down
4 changes: 2 additions & 2 deletions validation-test/compiler_crashers_2_fixed/0053-sr490.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend %s -emit-ir -swift-version 3
// RUN: %target-swift-frontend %s -emit-ir

enum Value {
case IntValue(Int)
Expand All @@ -13,7 +13,7 @@ protocol Storable {

protocol RawProducable {
var rawValueForType : Int16 { get }
init<T: Storable where T.Representation == Self>(value: T)
init<T: Storable>(value: T) where T.Representation == Self
}

extension Int : Storable {
Expand Down
10 changes: 4 additions & 6 deletions validation-test/compiler_crashers_2_fixed/0060-sr2702.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-swift-frontend %s -emit-ir -swift-version 3
// RUN: %target-swift-frontend %s -emit-ir -O -swift-version 3
// RUN: %target-swift-frontend %s -emit-ir
// RUN: %target-swift-frontend %s -emit-ir -O

// REQUIRES: objc_interop

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

let classesPtr = memory.assumingMemoryBound(to: Optional<AnyClass>.self)
let classes = AutoreleasingUnsafeMutablePointer<AnyClass?>(classesPtr)
let classes = AutoreleasingUnsafeMutablePointer<AnyClass>(classesPtr)
numClasses = objc_getClassList(classes, numClasses)

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

guard let cl = classes[i] else {
continue
}
let cl = classes[i]

if XUClassKindOfClass(cl, wantedSuperclass: aClass) && cl != aClass {
result.append(cl as! T.Type)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-swift-frontend %s -emit-ir

protocol P {}

class Base<T: P> {}

class Derived: Base<Derived>, P {}
Loading