-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[ClangImporter] Ignore redeclared properties with different types #6175
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
jrose-apple
merged 2 commits into
swiftlang:master
from
jrose-apple:bad-property-redeclaration
Dec 12, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/ClangImporter/Inputs/custom-modules/RedeclaredProperties/RPFirst.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@interface RPFoo | ||
@property (readonly, nonnull) int *nonnullToNullable; | ||
@property (readonly, nullable) int *nullableToNonnull; | ||
@property (readonly, nonnull) id typeChangeMoreSpecific; | ||
@property (readonly, nonnull) RPFoo *typeChangeMoreGeneral; | ||
|
||
@property (readonly, nonnull) id accessorRedeclaredAsNullable; | ||
- (nullable id)accessorRedeclaredAsNullable; | ||
|
||
- (nullable id)accessorDeclaredFirstAsNullable; | ||
@property (readonly, nonnull) id accessorDeclaredFirstAsNullable; | ||
@end |
6 changes: 6 additions & 0 deletions
6
test/ClangImporter/Inputs/custom-modules/RedeclaredProperties/RPSecond.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@interface RPFoo () | ||
@property (readwrite, nullable) int *nonnullToNullable; | ||
@property (readwrite, nonnull) int *nullableToNonnull; | ||
@property (readwrite, nonnull) RPFoo *typeChangeMoreSpecific; | ||
@property (readwrite, nonnull) id typeChangeMoreGeneral; | ||
@end |
2 changes: 2 additions & 0 deletions
2
test/ClangImporter/Inputs/custom-modules/RedeclaredProperties/RedeclaredProperties.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#import "RPFirst.h" | ||
#import "RPSecond.h" |
1 change: 1 addition & 0 deletions
1
test/ClangImporter/Inputs/custom-modules/RedeclaredProperties/RedeclaredPropertiesSplit.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#import "RPFirst.h" |
2 changes: 2 additions & 0 deletions
2
test/ClangImporter/Inputs/custom-modules/RedeclaredProperties/RedeclaredPropertiesSplit2.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#import "RedeclaredPropertiesSplit.h" | ||
#import "RPSecond.h" |
1 change: 1 addition & 0 deletions
1
test/ClangImporter/Inputs/custom-modules/RedeclaredProperties/RedeclaredPropertiesSub.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#import "RPFirst.h" |
2 changes: 2 additions & 0 deletions
2
...ClangImporter/Inputs/custom-modules/RedeclaredProperties/RedeclaredPropertiesSubPrivate.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#import "RedeclaredPropertiesSub.h" | ||
#import "RPSecond.h" |
22 changes: 22 additions & 0 deletions
22
test/ClangImporter/Inputs/custom-modules/RedeclaredProperties/module.modulemap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module RedeclaredPropertiesTextual { | ||
textual header "RPFirst.h" | ||
textual header "RPSecond.h" | ||
} | ||
|
||
module RedeclaredProperties { | ||
header "RedeclaredProperties.h" | ||
} | ||
|
||
module RedeclaredPropertiesSub { | ||
header "RedeclaredPropertiesSub.h" | ||
explicit module Private { | ||
header "RedeclaredPropertiesSubPrivate.h" | ||
} | ||
} | ||
|
||
module RedeclaredPropertiesSplit { | ||
header "RedeclaredPropertiesSplit.h" | ||
} | ||
module RedeclaredPropertiesSplit2 { | ||
header "RedeclaredPropertiesSplit2.h" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules -D ONE_MODULE %s -verify | ||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules -D SUB_MODULE %s -verify | ||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules -D TWO_MODULES %s -verify | ||
|
||
// REQUIRES: objc_interop | ||
|
||
#if ONE_MODULE | ||
import RedeclaredProperties | ||
#elseif SUB_MODULE | ||
import RedeclaredPropertiesSub | ||
import RedeclaredPropertiesSub.Private | ||
#elseif TWO_MODULES | ||
import RedeclaredPropertiesSplit | ||
import RedeclaredPropertiesSplit2 | ||
#endif | ||
|
||
func test(obj: RPFoo) { | ||
if let _ = obj.nonnullToNullable {} // expected-error {{initializer for conditional binding must have Optional type}} | ||
obj.nonnullToNullable = obj // expected-error {{cannot assign to property: 'nonnullToNullable' is a get-only property}} | ||
|
||
if let _ = obj.nullableToNonnull {} // okay | ||
obj.nullableToNonnull = obj // expected-error {{cannot assign to property: 'nullableToNonnull' is a get-only property}} | ||
|
||
let _: RPFoo = obj.typeChangeMoreSpecific // expected-error {{cannot convert value of type 'Any' to specified type 'RPFoo'}} | ||
obj.typeChangeMoreSpecific = obj // expected-error {{cannot assign to property: 'typeChangeMoreSpecific' is a get-only property}} | ||
|
||
let _: RPFoo = obj.typeChangeMoreGeneral | ||
obj.typeChangeMoreGeneral = obj // expected-error {{cannot assign to property: 'typeChangeMoreGeneral' is a get-only property}} | ||
|
||
if let _ = obj.accessorRedeclaredAsNullable {} // expected-error {{initializer for conditional binding must have Optional type}} | ||
if let _ = obj.accessorDeclaredFirstAsNullable {} // expected-error {{initializer for conditional binding must have Optional type}} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the mapTypeIntoContext() calls are unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried just comparing the interface types and it actually failed, because sometimes the interface type of the property was a generic parameter but the interface type of an accessor was a concrete type. Or vice versa.