-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2481,16 +2481,17 @@ class CompletionLookup final : public swift::VisibleDeclConsumer { | |
// What's left is the result type. | ||
if (ResultType->isVoid()) { | ||
OS << "Void"; | ||
} else if (!IsImplicitlyCurriedInstanceMethod | ||
&& FD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>()) { | ||
} else { | ||
// 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(); | ||
OS << "!"; | ||
} else { | ||
ResultType.print(OS); | ||
bool IsIUO = | ||
!IsImplicitlyCurriedInstanceMethod && | ||
FD->getAttrs().hasAttribute<ImplicitlyUnwrappedOptionalAttr>(); | ||
|
||
PrintOptions PO; | ||
PO.PrintOptionalAsImplicitlyUnwrapped = IsIUO; | ||
ResultType.print(OS, PO); | ||
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. This fix is going to cause other problems. All optionals will be printed with This applies to the earlier fix for parameters as well. 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 don't think so. This option only applies to the first Optional found. I will add a test case for it. 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. Ah yes, you're right, I had forgotten the code ensured that. |
||
} | ||
} | ||
Builder.addTypeAnnotation(TypeStr); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -372,13 +372,8 @@ class CodeCompletionResultBuilder { | |
|
||
PrintOptions PO; | ||
PO.SkipAttributes = true; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. In theory, this shouldn't crash. But this crash was caused by 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 |
||
} else { | ||
TypeName = Ty->getString(PO); | ||
} | ||
PO.PrintOptionalAsImplicitlyUnwrapped = IsIUO; | ||
std::string TypeName = Ty->getString(PO); | ||
addChunkWithText(CodeCompletionString::Chunk::ChunkKind::CallParameterType, | ||
TypeName); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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.