Skip to content

[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

Merged
merged 1 commit into from
Jul 26, 2018

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jul 25, 2018

Other instances of fb9c65e. Consistently use PrintOption.PrintOptionalAsImplicitlyUnwrapped to print IUO.

rdar://problem/41046225
rdar://problem/42443512

@rintaro rintaro requested a review from rudkx July 25, 2018 09:32
@rintaro
Copy link
Member Author

rintaro commented Jul 25, 2018

@swift-ci Please smoke test

std::string TypeName;
if (IsIUO) {
assert(Ty->getOptionalObjectType());
TypeName = Ty->getOptionalObjectType()->getStringAsComponent(PO) + "!";
Copy link
Member Author

@rintaro rintaro Jul 25, 2018

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();
Copy link
Member Author

@rintaro rintaro Jul 25, 2018

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?

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@rintaro rintaro force-pushed the ide-complete-printiuo branch from 28cff84 to 4d61774 Compare July 25, 2018 22:29
@rintaro
Copy link
Member Author

rintaro commented Jul 25, 2018

@swift-ci Please smoke test

Other instances of fb9c65e. Consistently use
PrintOption.PrintOptionalAsImplicitlyUnwrapped to print IUO.

rdar://problem/41046225
rdar://problem/42443512
@rintaro rintaro force-pushed the ide-complete-printiuo branch from 4d61774 to 9e7fa99 Compare July 25, 2018 22:55
@rintaro
Copy link
Member Author

rintaro commented Jul 25, 2018

Resolved conflict.
@swift-ci Please smoke test

@rintaro rintaro merged commit b5aa4ab into swiftlang:master Jul 26, 2018
@rintaro rintaro deleted the ide-complete-printiuo branch July 26, 2018 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants