-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Allow using std::map
subscript
#61385
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
Conversation
7c6b552
to
9faa409
Compare
@swift-ci please smoke test |
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.
Thanks!
if (!typeDecl || !parameterType) | ||
return nullptr; | ||
if (parameter->isInOut()) | ||
// Subscripts with inout parameters are not allowed in Swift. | ||
return nullptr; |
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.
We should transform this to a non-inout parameter.
If you're not going to fix this in the next week or two please add a diagnostic here as well.
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.
Oh I missed what this is actually doing, this makes the other overload becomes usable. This is lower priority, then.
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.
It's quite challenging to add a useful diagnostic here, since this method only gets invoked from generated Swift code. I think it's not worth the trouble, but let's discuss if you disagree 😉
9faa409
to
eaee8b5
Compare
@swift-ci please smoke test |
@swift-ci please smoke test |
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.
Awesome, lgtm :-)
This fixes an error that occurred when trying to use the subscript on an instance `std::map`: ``` error: cannot assign through subscript: 'map' is immutable ``` This was happening even with a mutable `std::map` instance. `std::map::operator[]` has two overloads: * `T& operator[]( const Key& key )` * `T& operator[]( Key&& key )` The second one is imported with an `inout` parameter, and we picked it as an implementation of the subscript getter because it was the last of the two overloads to get imported. Swift does not allow subscripts with `inout` parameters. This is checked at the AST level, and those checks do not run for synthesized Swift code. This caused Swift to produce a surprising error which actually indicated that the argument of the subscript, not the instance itself, must be mutable. rdar://100529571
eaee8b5
to
e28605c
Compare
The test failure on Linux is quite unfortunate but it is a different issue, I'll address it separately (#61412). |
@swift-ci please smoke test |
This fixes an error that occurred when trying to use the subscript on an instance
std::map
:This was happening even with a mutable
std::map
instance.std::map::operator[]
has two overloads:T& operator[]( const Key& key )
T& operator[]( Key&& key )
The second one is imported with an
inout
parameter, and we picked it as an implementation of the subscript getter because it was the last of the two overloads to get imported.Swift does not allow subscripts with
inout
parameters. This is checked at the AST level, and those checks do not run for synthesized Swift code. This caused Swift to produce a surprising error which actually indicated that the argument of the subscript, not the instance itself, must be mutable.rdar://100529571