Skip to content

rdar://problem/26424505 Import as Member: QoI errors #2650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apinotes/CoreGraphics.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Functions:
- Name: CGBitmapContextCreateWithData
SwiftName: CGContextRef.init(data:width:height:bitsPerComponent:bytesPerRow:space:bitmapInfo:releaseCallback:releaseInfo:)
- Name: CGBitmapContextCreate
SwiftName: CGContextRef.init(data:width:height:bitsPerComponent:bytesPerRow:space:bitmapInfo)
SwiftName: CGContextRef.init(data:width:height:bitsPerComponent:bytesPerRow:space:bitmapInfo:)
- Name: CGBitmapContextGetData
SwiftName: getter:CGContextRef.data(self:)
- Name: CGBitmapContextGetWidth
Expand Down
14 changes: 14 additions & 0 deletions test/APINotes/Inputs/broken-modules/BrokenAPINotes.apinotes
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Name: BrokenAPINotes
Functions:
- Name: ZXSpectrumGetAccumulator
SwiftName: 'getter:ZXSpectrum.accumulator(self:)'
- Name: ZXSpectrumSetAccumulator
SwiftName: 'setter:ZXSpectrum.accumulator(self:newValue:)'
- Name: ZXSpectrumGetRegister
SwiftName: 'getter:ZXSpectrum.register(self:which:)'
- Name: ZXSpectrumSetRegister
SwiftName: 'setter:ZXSpectrum.register(self:which:newValue:)'
- Name: ZXSpectrumGetMisnamedRegister
SwiftName: 'getter:ZXSpectrum.misnamedRegister(self:)'
- Name: ZXSpectrumSetMisnamedRegister
SwiftName: 'setter:ZXSpectrum.misnamedRegister(self:newValue:)'
11 changes: 11 additions & 0 deletions test/APINotes/Inputs/broken-modules/BrokenAPINotes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
typedef struct ZXSpectrum { unsigned char A, B, C, D, H, L; } ZXSpectrum;

unsigned char ZXSpectrumGetAccumulator(const ZXSpectrum *self);
void ZXSpectrumSetAccumulator(ZXSpectrum *self, unsigned char newValue);

unsigned char ZXSpectrumGetRegister(const ZXSpectrum *self, int which);
void ZXSpectrumSetRegister(ZXSpectrum *self, int which, unsigned char newValue);

unsigned char ZXSpectrumGetMisnamedRegister(const ZXSpectrum *self, int which);
void ZXSpectrumSetMisnamedRegister(ZXSpectrum *self, int which, unsigned char newValue);

3 changes: 3 additions & 0 deletions test/APINotes/Inputs/broken-modules/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module BrokenAPINotes {
header "BrokenAPINotes.h"
}
24 changes: 24 additions & 0 deletions test/APINotes/broken-swift-name.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %target-parse-verify-swift -I %S/Inputs/broken-modules
import BrokenAPINotes

func testBrokenSwiftName(x: inout ZXSpectrum) {
_ = x.accumulator
x.accumulator = 0

// The functions that import as `register`'s accessors have incorrect
// signatures for a getter or setter. Ensure we drop the import instead of
// forming an invalid property.
_ = x.register // expected-error{{has no member}}
x.register = 0 // expected-error{{has no member}}

_ = x.misnamedRegister // expected-error{{has no member}}
x.misnamedRegister = 0 // expected-error{{has no member}}

// Ensure that definitions with invalid API notes are still available
// under their original names.
ZXSpectrumGetRegister(&x, 0)
ZXSpectrumSetRegister(&x, 0, 1)
ZXSpectrumGetMisnamedRegister(&x, 0)
// TODO: Conservative validation in Clang doesn't reject the API name here
// ZXSpectrumSetMisnamedRegister(&x, 0, 1)
}
4 changes: 2 additions & 2 deletions test/ClangModules/Inputs/custom-modules/SwiftName.apinotes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Enumerators:
SwiftName: challenging
Functions:
- Name: spuriousAPINotedSwiftName
SwiftName: spuriousAPINotedSwiftName
SwiftName: spuriousAPINotedSwiftName(_:)
- Name: poorlyNamedFunction
SwiftName: nicelyRenamedFunction
SwiftName: nicelyRenamedFunction(_:)
2 changes: 1 addition & 1 deletion test/IDE/Inputs/custom-modules/ImportAsMember.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern double IAMStruct1GlobalVar
extern struct IAMStruct1 IAMStruct1CreateSimple(double value)
__attribute__((swift_name("Struct1.init(value:)")));

extern struct IAMStruct1 IAMStruct1CreateSpecialLabel()
extern struct IAMStruct1 IAMStruct1CreateSpecialLabel(void)
__attribute__((swift_name("Struct1.init(specialLabel:)")));

extern struct IAMStruct1 IAMStruct1Invert(struct IAMStruct1 s)
Expand Down
4 changes: 1 addition & 3 deletions test/IDE/Inputs/custom-modules/ImportAsMemberError.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ typedef NSObject<ImportedProtocolBase> *ImportedProtocolBase_t;
typedef NSObject<ErrorProto> *ErrorProto_t;

// Instance and static member onto protocol
void mutateSomeStaticState()
void mutateSomeStaticState(void)
__attribute__((swift_name("ErrorProto.mutateSomeStaticState()"))); // ok
void mutateSomeInstanceState(ErrorProto_t self) __attribute__((
swift_name("ErrorProto.mutateSomeInstanceState(self:)"))); // error

// Non-prototype declaration
extern void IAMErrorStructHasPrototype(void)
__attribute__((swift_name("ErrorStruct.hasPrototype()"))); // ok
extern void IAMErrorStructNonPrototype()
__attribute__((swift_name("ErrorStruct.nonPrototype()"))); // error

#endif // IMPORT_AS_MEMBER_ERR_H
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty much the entire thing being tested, and now the comment is wrong. If there's a test on the Clang side I'm okay with removing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my thinking; now that we have better Clang-side validation and just throw the attr away if it's invalid, this wasn't really nonredundantly testing anything anymore.

2 changes: 0 additions & 2 deletions test/IDE/import_as_member_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ import IAMError

// Errors
ErrorStruct.hasPrototype();
ErrorStruct.nonPrototype();
// expected-error@-1{{type 'ErrorStruct' has no member 'nonPrototype'}}

// Protocols
@objc class Foo : NSObject, IAMProto {}
Expand Down