Skip to content

Commit 884155c

Browse files
committed
[Import as member] Refactor testing.
Separate out error tests, so that we can more extensively test protocol and non-prototype errors. NFC
1 parent 4e4c511 commit 884155c

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef IMPORT_AS_MEMBER_ERR_H
2+
#define IMPORT_AS_MEMBER_ERR_H
3+
4+
struct __attribute__((swift_name("ErrorStruct"))) IAMStruct {
5+
double x, y, z;
6+
};
7+
8+
@import Foundation;
9+
10+
@protocol ImportedProtocolBase;
11+
@protocol ImportedProtocolBase <NSObject>
12+
@end
13+
typedef NSObject<ImportedProtocolBase> *ImportedProtocolBase_t;
14+
15+
@protocol ErrorProto;
16+
@protocol ErrorProto <ImportedProtocolBase>
17+
@end
18+
19+
typedef NSObject<ErrorProto> *ErrorProto_t;
20+
21+
// Instance and static member onto protocol
22+
void mutateSomeStaticState()
23+
__attribute__((swift_name("ErrorProto.mutateSomeStaticState()"))); // ok
24+
void mutateSomeInstanceState(ErrorProto_t self) __attribute__((
25+
swift_name("ErrorProto.mutateSomeInstanceState(self:)"))); // error
26+
27+
// Non-prototype declaration
28+
extern void IAMErrorStructHasPrototype(void)
29+
__attribute__((swift_name("ErrorStruct.hasPrototype()"))); // ok
30+
extern void IAMErrorStructNonPrototype()
31+
__attribute__((swift_name("ErrorStruct.nonPrototype()"))); // error
32+
33+
#endif // IMPORT_AS_MEMBER_ERR_H

test/IDE/Inputs/custom-modules/ImportAsMemberProtoErr.h

-10
This file was deleted.

test/IDE/Inputs/custom-modules/module.map

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ module ImportAsMember {
3131
requires objc
3232
header "ImportAsMemberProto.h"
3333
}
34+
}
3435

35-
module ProtoErr {
36-
requires objc
37-
header "ImportAsMemberProto.h"
38-
}
36+
module IAMError {
37+
export *
38+
requires objc
39+
header "ImportAsMemberError.h"
3940
}
4041

4142
module InferImportAsMember {

test/IDE/import_as_member.swift

+16-8
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@
6767

6868
// REQUIRES: objc_interop
6969

70-
import ImportAsMember
70+
import Foundation
71+
import ImportAsMember.A
7172
import ImportAsMember.B
72-
import ImportAsMember.ProtoErr
73+
import ImportAsMember.Proto
74+
import IAMError
7375

7476
let iamStructFail = IAMStruct1CreateSimple()
7577
// expected-error@-1{{use of unresolved identifier 'IAMStruct1CreateSimple'}}
@@ -96,19 +98,25 @@ iamStruct = Struct1.zero
9698
// Global properties
9799
currentStruct1.x += 1.5
98100

101+
ErrorStruct.hasPrototype();
102+
ErrorStruct.nonPrototype();
103+
// expected-error@-1{{type 'ErrorStruct' has no member 'nonPrototype'}}
104+
99105
// Protocols
100-
// class Foo : NSObject, IAMProto {}
106+
@objc class Foo : NSObject, IAMProto {}
101107

102108
struct Bar : IAMProto {}
103109
// expected-error@-1{{non-class type 'Bar' cannot conform to class protocol 'IAMProto'}}
104110
// expected-error@-2{{non-class type 'Bar' cannot conform to class protocol 'ImportedProtocolBase'}}
105111
// expected-error@-3{{non-class type 'Bar' cannot conform to class protocol 'NSObjectProtocol'}}
106112

113+
@objc class FooErr : NSObject, ErrorProto {}
107114

108-
// let foo = Foo()
109-
// foo.mutateSomeState()
110-
// Foo.mutateSomeStaticState()
111-
// expected-not-error@-1{{type 'Foo' has no member 'mutateSomeStaticState'}}
115+
let foo = Foo()
116+
foo.mutateSomeState()
112117

113-
// TODO: error: "swift_name cannot be used to define static member on protocol"
118+
let fooErr = FooErr()
119+
fooErr.mutateSomeInstanceState()
120+
FooErr.mutateSomeStaticState()
121+
// expected-error@-1{{type 'FooErr' has no member 'mutateSomeStaticState'}}
114122

0 commit comments

Comments
 (0)