Skip to content

[InlinableText] Handle multiline #if conditions #19675

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
Oct 3, 2018

Conversation

harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Oct 3, 2018

Previously, a #if of the form:

#if (
  false
)
print("x")
#endif

Would be emitted after #if-stripping as

  false
)
print("x")

Because the old logic assumed conditions will always appear on one line.
Instead, for active clauses that have conditions, skip to the next line
after the end of the condition instead.

@harlanhaskins harlanhaskins force-pushed the inline-skating branch 3 times, most recently from ce1a473 to f499ecd Compare October 3, 2018 00:06
// CHECK-NOT: #if (
// CHECK-NOT: false && !true
// CHECK-NOT: )
// CHECK-NOT: print("should not appear")
Copy link
Member

@rintaro rintaro Oct 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think this test case it not testing the code change.
The change affects only for getActiveClause(), but this block is not active...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code we have actually looks for inactive ranges, but I think you're right that we should see what happens with a multi-line active range too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant this test case should pass even without the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rintaro You're right, I pushed before testing locally 😅 They should pass now.

// CHECK: print("should appear")
// CHECK-NOT: #endif
// CHECK-NEXT: })
public func hasClosureDefaultArgWithMultilinePoundIfCondition(_ x: () -> Void) = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe ) after () -> Void is not intentional.

Previously, a #if of the form:

```swift
#if (
  false
)
print("x")
#endif
```

Would be emitted after #if-stripping as

```swift
  false
)
print("x")
```

Because the old logic assumed conditions will always appear on one line.
Instead, for active clauses that have conditions, skip to the next line
after the end of the condition instead.
@harlanhaskins
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@harlanhaskins harlanhaskins merged commit 8061358 into swiftlang:master Oct 3, 2018
modelorganism pushed a commit to modelorganism/swift that referenced this pull request Oct 11, 2018
Previously, a #if of the form:

```swift
#if (
  false
)
print("x")
#endif
```

Would be emitted after #if-stripping as

```swift
  false
)
print("x")
```

Because the old logic assumed conditions will always appear on one line.
Instead, for active clauses that have conditions, skip to the next line
after the end of the condition instead.
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.

3 participants