Files
swift-mirror/test/Constraints/generic_super_constraint.swift
Doug Gregor cdb38c1e97 [GSB] Check all superclass constraints during finalization.
Use the same infrastructure we have for same-type-to-concrete
constraints to check superclass constraints. Specifically,

* Track all superclass constraints; never "update" a requirement source
* Remove self-derived superclass constraints
* Pick the best superclass constraint within each connected component
  of an equivalence class and use that for requirement generation.
* Diagnose conflicting superclass requirements during finalization
* Diagnose redundant superclass requirements (during finalization)
2017-02-28 16:14:30 -08:00

20 lines
704 B
Swift

// RUN: %target-swift-frontend %s -typecheck -verify
class Base<T> { }
class Derived: Base<Int> { }
func foo<T>(_ x: T) -> Derived where T: Base<Int>, T: Derived {
// expected-warning@-1{{redundant superclass constraint 'T' : 'Base<Int>'}}
// expected-note@-2{{superclass constraint 'T' : 'Derived' written here}}
return x
}
// FIXME: Should not be an error
// expected-error@+2{{generic parameter 'U' cannot be a subclass of both 'Derived' and 'Base<T>'}}
// expected-note@+1{{superclass constraint 'U' : 'Base<T>' written here}}
func bar<T, U>(_ x: U, y: T) -> (Derived, Int) where U: Base<T>, U: Derived {
// FIXME
// expected-error@+1{{cannot convert return expression}}
return (x, y)
}