Skip to content

[ASTGen] Generate Swift key-path expressions #77398

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
Nov 6, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Nov 5, 2024

No description provided.

@rintaro
Copy link
Member Author

rintaro commented Nov 5, 2024

@swift-ci Please smoke test


// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -dump-ast -enable-experimental-feature ParserASTGen -verify > %t/astgen.ast.raw
// RUN: not %target-swift-frontend %s -dump-ast > %t/cpp-parser.ast.raw
Copy link
Member Author

@rintaro rintaro Nov 5, 2024

Choose a reason for hiding this comment

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

Comparing -dump-ast instead of -dump-parse because we generate KeyPathExpr differently.
In libParse the root expression is parsed as a normal expression, but in SwiftParser it's parsed as a TypeSyntax, so we generate it as TypeExpr. But they are normalized in PreCheckTarget and should be end up with the same type-checked AST.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth adding this as a comment to the test?

var i = \[A].property.nonMutatingProperty
expect(&i, toHaveType: Exactly<ReferenceWritableKeyPath<[A], B>>.self)

var j = \[A].[x]
Copy link
Contributor

Choose a reason for hiding this comment

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

Amusingly you can also do \[A][x] 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm I thought we require a dot if the first "path" part is a subscript. But apparently not 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW this cases are pulled from test/expr/unary/keypath/keypath.swift And I will add more test cases from it when I revisit here for adding AST diagnostics (for e.g. empty components)

@rintaro rintaro force-pushed the astgen-keypathexpr branch from c4d183d to dc156a6 Compare November 5, 2024 21:38
@rintaro
Copy link
Member Author

rintaro commented Nov 5, 2024

@swift-ci Please smoke test

@rintaro rintaro enabled auto-merge November 6, 2024 00:47
@rintaro
Copy link
Member Author

rintaro commented Nov 6, 2024

@swift-ci Please smoke test Windows

1 similar comment
@rintaro
Copy link
Member Author

rintaro commented Nov 6, 2024

@swift-ci Please smoke test Windows

@rintaro rintaro merged commit 47f27a4 into swiftlang:main Nov 6, 2024
3 checks passed
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