mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Today ParenType is used: 1. As the type of ParenExpr 2. As the payload type of an unlabeled single associated value enum case (and the type of ParenPattern). 3. As the type for an `(X)` TypeRepr For 1, this leads to some odd behavior, e.g the type of `(5.0 * 5).squareRoot()` is `(Double)`. For 2, we should be checking the arity of the enum case constructor parameters and the presence of ParenPattern respectively. Eventually we ought to consider replacing Paren/TuplePattern with a PatternList node, similar to ArgumentList. 3 is one case where it could be argued that there's some utility in preserving the sugar of the type that the user wrote. However it's really not clear to me that this is particularly desirable since a bunch of diagnostic logic is already stripping ParenTypes. In cases where we care about how the type was written in source, we really ought to be consulting the TypeRepr.
33 lines
1.4 KiB
Swift
33 lines
1.4 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
class Base {
|
|
func foo() {}
|
|
}
|
|
|
|
class Sub: Base {
|
|
override func foo() {}
|
|
}
|
|
|
|
func removeOverrides<SomeSub: Sub>(concrete: Sub, generic: SomeSub) {
|
|
concrete.foo()
|
|
generic.foo()
|
|
}
|
|
|
|
class Base1 {
|
|
func foo1(a : Int, b : @escaping () -> ()) {} // expected-note{{potential overridden instance method 'foo1(a:b:)' here}}
|
|
func foo2(a : @escaping (Int)->(Int), b : @escaping () -> ()) {} // expected-note{{potential overridden instance method 'foo2(a:b:)' here}}
|
|
}
|
|
|
|
class Sub1 : Base1 {
|
|
override func foo1(a : Int, b : () -> ()) {} // expected-error {{method does not override any method from its superclass}} expected-note {{type does not match superclass instance method with type '(Int, @escaping () -> ()) -> ()'}} {{34-34=@escaping }}
|
|
override func foo2(a : (Int)->(Int), b : () -> ()) {} // expected-error {{method does not override any method from its superclass}} expected-note{{type does not match superclass instance method with type '(@escaping (Int) -> Int, @escaping () -> ()) -> ()'}} {{25-25=@escaping }} {{43-43=@escaping }}
|
|
}
|
|
|
|
class Base2 {
|
|
func foo<T>(a : @escaping (T) -> ()) {} // expected-note{{potential overridden instance method 'foo(a:)' here}}
|
|
}
|
|
|
|
class Sub2 : Base2 {
|
|
override func foo<T>(a : (T) -> ()) {} // expected-error {{method does not override any method from its superclass}} expected-note{{type does not match superclass instance method with type '(@escaping (T) -> ()) -> ()'}}{{28-28=@escaping }}
|
|
}
|