-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CodeComplete] Use PrintOptionalAsImplicitlyUnwrapped to print IUO #18217
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
@swift-ci Please smoke test |
std::string TypeName; | ||
if (IsIUO) { | ||
assert(Ty->getOptionalObjectType()); | ||
TypeName = Ty->getOptionalObjectType()->getStringAsComponent(PO) + "!"; |
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.
In theory, this shouldn't crash. But this crash was caused by
https://github.com/apple/swift/blob/e9cb62d476496787ccc92c506e9059db58c96614/lib/IDE/CodeCompletion.cpp#L2177-L2180
This hack is not enough.
In fact, this fix still doesn't produce correct result, but at least, it fixes the crashes. I want to include this fix for 4.2. I will fix this FIXME
for later releases.
// As we did with parameters in addParamPatternFromFunction, | ||
// for regular methods we'll print '!' after implicitly | ||
// unwrapped optional results. | ||
auto ObjectType = ResultType->getOptionalObjectType(); | ||
OS << ObjectType->getStringAsComponent(); |
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 couldn't find a reproducer for this crash. But we have several logs crashed in here. It means, result type is resolved as non-optional even when the function decl has ImplicitlyUnwrappedOptionalAttr
.
@rudkx Are you able to come up with a possibility that causes this situation?
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.
The only thing I can think of is that this is related to the adjustment of FunctionType
earlier in the function.
|
||
PrintOptions PO; | ||
PO.PrintOptionalAsImplicitlyUnwrapped = IsIUO; | ||
ResultType.print(OS, PO); |
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.
This fix is going to cause other problems. All optionals will be printed with !
, so if e.g. if you try your change with a function that returns [Int?]!
, I think you'll find it prints as [Int!]!
.
This applies to the earlier fix for parameters 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.
I don't think so. This option only applies to the first Optional found.
https://github.com/apple/swift/blob/master/lib/AST/ASTPrinter.cpp#L3748-L3754
I will add a test case for it.
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.
Ah yes, you're right, I had forgotten the code ensured that.
28cff84
to
4d61774
Compare
@swift-ci Please smoke test |
Other instances of fb9c65e. Consistently use PrintOption.PrintOptionalAsImplicitlyUnwrapped to print IUO. rdar://problem/41046225 rdar://problem/42443512
4d61774
to
9e7fa99
Compare
Resolved conflict. |
Other instances of fb9c65e. Consistently use
PrintOption.PrintOptionalAsImplicitlyUnwrapped
to print IUO.rdar://problem/41046225
rdar://problem/42443512