// Verify errors in this file to ensure that parse and type checker errors // occur where we expect them. // RUN: %target-parse-verify-swift -show-diagnostics-after-fatal %s // RUN: %target-swift-ide-test -print-ast-typechecked -source-filename %s -prefer-type-repr=false > %t.printed.txt // RUN: FileCheck %s -strict-whitespace < %t.printed.txt // RUN: FileCheck -check-prefix=NO-TYPEREPR %s -strict-whitespace < %t.printed.txt // RUN: %target-swift-ide-test -print-ast-typechecked -source-filename %s -prefer-type-repr=true > %t.printed.txt // RUN: FileCheck %s -strict-whitespace < %t.printed.txt // RUN: FileCheck -check-prefix=TYPEREPR %s -strict-whitespace < %t.printed.txt //===--- //===--- Helper types. //===--- class FooClass {} class BarClass {} protocol FooProtocol {} protocol BarProtocol {} protocol BazProtocol { func baz() } protocol QuxProtocol { associatedtype Qux } class FooProtocolImpl : FooProtocol {} class FooBarProtocolImpl : FooProtocol, BarProtocol {} class BazProtocolImpl : BazProtocol { func baz() {} } //===--- //===--- Import printing. //===--- import not_existent_module_a // expected-error{{no such module 'not_existent_module_a'}} // CHECK: {{^}}import not_existent_module_a{{$}} import not_existent_module_a.submodule // expected-error{{no such module}} // CHECK-NEXT: {{^}}import not_existent_module_a.submodule{{$}} @_exported import not_existent_module_b // expected-error{{no such module 'not_existent_module_b'}} // CHECK-NEXT: {{^}}@_exported import not_existent_module_b{{$}} @_exported import not_existent_module_b.submodule // expected-error{{no such module}} // CHECK-NEXT: {{^}}@_exported import not_existent_module_b.submodule{{$}} import struct not_existent_module_c.foo // expected-error{{no such module 'not_existent_module_c'}} // CHECK-NEXT: {{^}}import struct not_existent_module_c.foo{{$}} import class not_existent_module_c.foo // expected-error{{no such module 'not_existent_module_c'}} // CHECK-NEXT: {{^}}import class not_existent_module_c.foo{{$}} import enum not_existent_module_c.foo // expected-error{{no such module 'not_existent_module_c'}} // CHECK-NEXT: {{^}}import enum not_existent_module_c.foo{{$}} import protocol not_existent_module_c.foo // expected-error{{no such module 'not_existent_module_c'}} // CHECK-NEXT: {{^}}import protocol not_existent_module_c.foo{{$}} import var not_existent_module_c.foo // expected-error{{no such module 'not_existent_module_c'}} // CHECK-NEXT: {{^}}import var not_existent_module_c.foo{{$}} import func not_existent_module_c.foo // expected-error{{no such module 'not_existent_module_c'}} // CHECK-NEXT: {{^}}import func not_existent_module_c.foo{{$}} //===--- //===--- Inheritance list in structs. //===--- struct StructWithInheritance1 : FooNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // NO-TYPEREPR: {{^}}struct StructWithInheritance1 : <> {{{$}} // TYPEREPR: {{^}}struct StructWithInheritance1 : FooNonExistentProtocol {{{$}} struct StructWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} expected-error {{use of undeclared type 'BarNonExistentProtocol'}} // NO-TYPEREPR: {{^}}struct StructWithInheritance2 : <>, <> {{{$}} // TYPEREPR: {{^}}struct StructWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {{{$}} //===--- //===--- Inheritance list in classes. //===--- class ClassWithInheritance1 : FooNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // NO-TYREPR: {{^}}class ClassWithInheritance1 : <> {{{$}} // TYREPR: {{^}}class ClassWithInheritance1 : FooNonExistentProtocol {{{$}} class ClassWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} expected-error {{use of undeclared type 'BarNonExistentProtocol'}} // NO-TYREPR: {{^}}class ClassWithInheritance2 : <>, <> {{{$}} // TYREPR: {{^}}class ClassWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {{{$}} class ClassWithInheritance3 : FooClass, FooNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // NO-TYREPR: {{^}}class ClassWithInheritance3 : FooClass, <> {{{$}} // TYREPR: {{^}}class ClassWithInheritance3 : FooClass, FooNonExistentProtocol {{{$}} class ClassWithInheritance4 : FooProtocol, FooClass {} // expected-error {{superclass 'FooClass' must appear first in the inheritance clause}} {{31-31=FooClass, }} {{42-52=}} // CHECK: {{^}}class ClassWithInheritance4 : FooProtocol, FooClass {{{$}} class ClassWithInheritance5 : FooProtocol, BarProtocol, FooClass {} // expected-error {{superclass 'FooClass' must appear first in the inheritance clause}} {{31-31=FooClass, }} {{55-65=}} // CHECK: {{^}}class ClassWithInheritance5 : FooProtocol, BarProtocol, FooClass {{{$}} class ClassWithInheritance6 : FooClass, BarClass {} // expected-error {{multiple inheritance from classes 'FooClass' and 'BarClass'}} // NO-TYREPR: {{^}}class ClassWithInheritance6 : FooClass, <> {{{$}} // TYREPR: {{^}}class ClassWithInheritance6 : FooClass, BarClass {{{$}} class ClassWithInheritance7 : FooClass, BarClass, FooProtocol {} // expected-error {{multiple inheritance from classes 'FooClass' and 'BarClass'}} // NO-TYREPR: {{^}}class ClassWithInheritance7 : FooClass, <>, FooProtocol {{{$}} // TYREPR: {{^}}class ClassWithInheritance7 : FooClass, BarClass, FooProtocol {{{$}} class ClassWithInheritance8 : FooClass, BarClass, FooProtocol, BarProtocol {} // expected-error {{multiple inheritance from classes 'FooClass' and 'BarClass'}} // NO-TYREPR: {{^}}class ClassWithInheritance8 : FooClass, <>, FooProtocol, BarProtocol {{{$}} // TYREPR: {{^}}class ClassWithInheritance8 : FooClass, BarClass, FooProtocol, BarProtocol {{{$}} class ClassWithInheritance9 : FooClass, BarClass, FooProtocol, BarProtocol, FooNonExistentProtocol {} // expected-error {{multiple inheritance from classes 'FooClass' and 'BarClass'}} expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // NO-TYREPR: {{^}}class ClassWithInheritance9 : FooClass, <>, FooProtocol, BarProtocol, <> {{{$}} // TYREPR: {{^}}class ClassWithInheritance9 : FooClass, BarClass, FooProtocol, BarProtocol, FooNonExistentProtocol {{{$}} //===--- //===--- Inheritance list in enums. //===--- enum EnumWithInheritance1 : FooNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // expected-error@-1{{type 'EnumWithInheritance1' does not conform to protocol 'RawRepresentable'}} // NO-TYREPR: {{^}}enum EnumWithInheritance1 : <> {{{$}} // TYREPR: {{^}}enum EnumWithInheritance1 : FooNonExistentProtocol {{{$}} enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} expected-error {{use of undeclared type 'BarNonExistentProtocol'}} // expected-error@-1{{type 'EnumWithInheritance2' does not conform to protocol 'RawRepresentable'}} // NO-TYREPR: {{^}}enum EnumWithInheritance2 : <>, <> {{{$}} // TYREPR: {{^}}enum EnumWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {{{$}} enum EnumWithInheritance3 : FooClass { case X } // expected-error {{raw type 'FooClass' is not convertible from any literal}} // expected-error@-1{{type 'EnumWithInheritance3' does not conform to protocol 'RawRepresentable'}} // NO-TYREPR: {{^}}enum EnumWithInheritance3 : <> {{{$}} // TYREPR: {{^}}enum EnumWithInheritance3 : FooClass {{{$}} enum EnumWithInheritance4 : FooClass, FooProtocol { case X } // expected-error {{raw type 'FooClass' is not convertible from any literal}} // expected-error@-1{{type 'EnumWithInheritance4' does not conform to protocol 'RawRepresentable'}} // NO-TYREPR: {{^}}enum EnumWithInheritance4 : <>, FooProtocol {{{$}} // TYREPR: {{^}}enum EnumWithInheritance4 : FooClass, FooProtocol {{{$}} enum EnumWithInheritance5 : FooClass, BarClass { case X } // expected-error {{raw type 'FooClass' is not convertible from any literal}} expected-error {{multiple enum raw types 'FooClass' and 'BarClass'}} // expected-error@-1{{type 'EnumWithInheritance5' does not conform to protocol 'RawRepresentable'}} // NO-TYREPR: {{^}}enum EnumWithInheritance5 : <>, <> {{{$}} // TYREPR: {{^}}enum EnumWithInheritance5 : FooClass, BarClass {{{$}} //===--- //===--- Inheritance list in protocols. //===--- protocol ProtocolWithInheritance1 : FooNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // NO-TYREPR: {{^}}protocol ProtocolWithInheritance1 : <> {{{$}} // TYREPR: {{^}}protocol ProtocolWithInheritance1 : FooNonExistentProtocol {{{$}} protocol ProtocolWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {} // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} expected-error {{use of undeclared type 'BarNonExistentProtocol'}} // NO-TYREPR: {{^}}protocol ProtocolWithInheritance2 : <>, <> {{{$}} // TYREPR: {{^}}protocol ProtocolWithInheritance2 : FooNonExistentProtocol, BarNonExistentProtocol {{{$}} protocol ProtocolWithInheritance3 : FooClass {} // expected-error {{non-class type 'ProtocolWithInheritance3' cannot inherit from class 'FooClass'}} // NO-TYREPR: {{^}}protocol ProtocolWithInheritance3 : <> {{{$}} // TYREPR: {{^}}protocol ProtocolWithInheritance3 : FooClass {{{$}} protocol ProtocolWithInheritance4 : FooClass, FooProtocol {} // expected-error {{non-class type 'ProtocolWithInheritance4' cannot inherit from class 'FooClass'}} // NO-TYREPR: {{^}}protocol ProtocolWithInheritance4 : <>, FooProtocol {{{$}} // TYREPR: {{^}}protocol ProtocolWithInheritance4 : FooClass, FooProtocol {{{$}} protocol ProtocolWithInheritance5 : FooClass, BarClass {} // expected-error {{non-class type 'ProtocolWithInheritance5' cannot inherit from class 'FooClass'}} expected-error {{non-class type 'ProtocolWithInheritance5' cannot inherit from class 'BarClass'}} // NO-TYREPR: {{^}}protocol ProtocolWithInheritance5 : <>, <> {{{$}} // TYREPR: {{^}}protocol ProtocolWithInheritance5 : FooClass, BarClass {{{$}} //===--- //===--- Typealias printing. //===--- // Normal typealiases. typealias Typealias1 = FooNonExistentProtocol // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // NO-TYREPR: {{^}}typealias Typealias1 = <>{{$}} // TYREPR: {{^}}typealias Typealias1 = FooNonExistentProtocol{{$}} // sr-197 func foo(bar: Typealias1) {} // Should not generate error "cannot specialize non-generic type '<>'" // Associated types. protocol AssociatedType1 { // CHECK-LABEL: AssociatedType1 { associatedtype AssociatedTypeDecl1 : FooProtocol = FooClass // CHECK: {{^}} associatedtype AssociatedTypeDecl1 : FooProtocol = FooClass{{$}} associatedtype AssociatedTypeDecl2 : BazProtocol = FooClass // CHECK: {{^}} associatedtype AssociatedTypeDecl2 : BazProtocol = FooClass{{$}} associatedtype AssociatedTypeDecl3 : FooNonExistentProtocol // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} // NO-TYREPR: {{^}} associatedtype AssociatedTypeDecl3 : <>{{$}} // TYREPR: {{^}} associatedtype AssociatedTypeDecl3 : FooNonExistentProtocol{{$}} associatedtype AssociatedTypeDecl4 : FooNonExistentProtocol, BarNonExistentProtocol // expected-error {{use of undeclared type 'FooNonExistentProtocol'}} expected-error {{use of undeclared type 'BarNonExistentProtocol'}} // NO-TYREPR: {{^}} associatedtype AssociatedTypeDecl4 : <>, <>{{$}} // TYREPR: {{^}} associatedtype AssociatedTypeDecl4 : FooNonExistentProtocol, BarNonExistentProtocol{{$}} associatedtype AssociatedTypeDecl5 : FooClass // CHECK: {{^}} associatedtype AssociatedTypeDecl5 : FooClass{{$}} } //===--- //===--- Variable declaration printing. //===--- var topLevelVar1 = 42 // CHECK: {{^}}var topLevelVar1: Int{{$}} // CHECK-NOT: topLevelVar1 // CHECK: class C1 class C1 { // CHECK: init(data: <>) init(data:) // expected-error {{expected parameter type following ':'}} } protocol IllegalExtension {} class OuterContext { // CHECK: class OuterContext { extension IllegalExtension { // expected-error {{declaration is only valid at file scope}} // CHECK: extension IllegalExtension { func protocolFunc() {} // CHECK: func protocolFunc() } }