-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add '@_requiresConcreteImplementation' and use it #30417
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5948ba1
Add @_requiresConcreteImplementation attribute
xwu 82fb5d3
Add test for @_requiresConcreteImplementation
xwu bfbfec1
Reorder DeclTypeRecordNodes.def so that serialization of additional a…
xwu 5feb517
[stdlib] Adopt @_requiresConcreteImplementation for RandomNumberGener…
xwu 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
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
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 |
---|---|---|
|
@@ -134,7 +134,7 @@ DECL(PRECEDENCE_GROUP) | |
DECL(ACCESSOR) | ||
|
||
#ifndef DECL_ATTR | ||
#define DECL_ATTR(NAME, CLASS, OPTIONS, CODE) RECORD_VAL(CLASS##_DECL_ATTR, 100+CODE) | ||
#define DECL_ATTR(NAME, CLASS, OPTIONS, CODE) RECORD_VAL(CLASS##_DECL_ATTR, 90+CODE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not proud of this, but there are 99 existing decl attrs, so with one more we would otherwise crash into |
||
#endif | ||
#include "swift/AST/Attr.def" | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// RUN: %target-typecheck-verify-swift | ||
|
||
protocol P { | ||
@_requiresConcreteImplementation | ||
func f(_: Int) -> Bool // expected-note {{requirement 'f' declared here}} | ||
// expected-note@-1 {{overridden declaration is here}} | ||
func f<T: SignedInteger>(_: T) -> Bool | ||
|
||
func g(_: Int) -> Bool | ||
} | ||
|
||
extension P { | ||
func f<T: SignedInteger>(_ x: T) -> Bool { // expected-note {{'f' declared here}} | ||
return f(Int(x)) | ||
} | ||
|
||
func g(_ x: Int) -> Bool { // expected-note {{'g' declared here}} | ||
return f(x) | ||
} | ||
} | ||
|
||
protocol Q: P { | ||
override func f(_: Int) -> Bool // expected-error {{override of protocol requirement marked '@_requiresConcreteImplementation' should also be marked }} | ||
} | ||
|
||
protocol R: P { | ||
@_requiresConcreteImplementation | ||
override func g(_: Int) -> Bool // expected-note {{requirement 'g' declared here}} | ||
} | ||
|
||
struct S: P { // expected-error {{type 'S' does not conform to protocol 'P'}} | ||
// expected-error@-1 {{protocol requirement marked '@_requiresConcreteImplementation' cannot be satisfied }} | ||
} | ||
|
||
struct T: P, R { // expected-error {{type 'T' does not conform to protocol 'R'}} | ||
// expected-error@-1 {{protocol requirement marked '@_requiresConcreteImplementation' cannot be satisfied }} | ||
func f(_: Int) -> Bool { true } | ||
} | ||
|
||
struct U: R { | ||
func f(_: Int) -> Bool { true } | ||
func g(_: Int) -> Bool { false } | ||
} | ||
|
||
class C { | ||
@_requiresConcreteImplementation // expected-error {{'@_requiresConcreteImplementation' can only be specified on protocol requirements}} | ||
var x: Int = 42 | ||
} |
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.
APIBreakingToAdd
?