Files
swift-mirror/test/Parse/init_deinit.swift
Doug Gregor 3d77855b31 Start allowing extensions of protocol types.
Remove the semantic restrictions that prohibited extensions of
protocol types, and start making some systematic changes so that
protocol extensions start to make sense:
  - Replace a lot of occurrences of isa<ProtocolDecl> and
    dyn_cast<ProtocolDecl> on DeclContexts to use the new
    DeclContext::isProtocolOrProtocolExtensionContext(), where we want
    that behavior to apply equally to protocols and protocol extensions.
  - Eliminate ProtocolDecl::getSelf() in favor of
    DeclContext::getProtocolSelf(), which produces the appropriate
    generic type parameter for the 'Self' of a protocol or protocol
    extension. Update all of the callers of ProtocolDecl::getSelf()
    appropriately.
  - Update extension validation to appropriately form generic
    parameter lists for protocol extensions.
  - Methods in protocol extensions always use the witnesscc calling
  convention.

At this point, we can type check and SILGen very basic definitions of
protocol extensions with methods that can call protocol requirements,
generic free functions, and other methods within the same protocol
extension.

Regresses four compiler crashers but improves three compiler
crashers... we'll call that "progress"; the four regressions all hit
the same assertion in the constraint system that will likely be
addressed as protocol extensions starts working.

Swift SVN r26579
2015-03-26 04:50:51 +00:00

103 lines
2.8 KiB
Swift

// RUN: %target-parse-verify-swift
struct FooStructConstructorA {
init // expected-error {{expected '('}}
}
struct FooStructConstructorB {
init() // expected-error {{initializer requires a body}}
}
struct FooStructConstructorC {
init {} // expected-error {{expected '('}}{{8-8=() }}
}
struct FooStructDeinitializerA {
deinit // expected-error {{expected '{' for deinitializer}}
}
struct FooStructDeinitializerB {
deinit // expected-error {{expected '{' for deinitializer}}
}
struct FooStructDeinitializerC {
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
class FooClassDeinitializerA {
deinit(a : Int) {} // expected-error{{no parameter clause allowed on deinitializer}}{{9-18=}}
}
class FooClassDeinitializerB {
deinit { }
}
init {} // expected-error {{initializers may only be declared within a type}} expected-error {{expected '('}}
init() // expected-error {{initializers may only be declared within a type}}
init() {} // expected-error {{initializers may only be declared within a type}}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
deinit // expected-error {{expected '{' for deinitializer}}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
struct BarStruct {
init() {}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
extension BarStruct {
init(x : Int) {}
// When/if we allow 'var' in extensions, then we should also allow dtors
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
enum BarUnion {
init() {}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
extension BarUnion {
init(x : Int) {}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
class BarClass {
init() {}
deinit {}
}
extension BarClass {
convenience init(x : Int) { self.init() }
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
protocol BarProtocol {
init() {} // expected-error {{protocol initializers may not have bodies}}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
extension BarProtocol {
init(x : Int) {}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
func fooFunc() {
init() {} // expected-error {{initializers may only be declared within a type}}
deinit {} // expected-error {{deinitializers may only be declared within a class}}
}
func barFunc() {
var x : () = { () -> () in
init() {} // expected-error {{initializers may only be declared within a type}}
return
} ()
var y : () = { () -> () in
deinit {} // expected-error {{deinitializers may only be declared within a class}}
return
} ()
}