Skip to content

[SwiftLexicalLookup] Add ScopeSyntax conformance for EnumCaseDeclSyntax#3280

Open
Ronitsabhaya75 wants to merge 1 commit intoswiftlang:mainfrom
Ronitsabhaya75:enum-case-scope-lookup
Open

[SwiftLexicalLookup] Add ScopeSyntax conformance for EnumCaseDeclSyntax#3280
Ronitsabhaya75 wants to merge 1 commit intoswiftlang:mainfrom
Ronitsabhaya75:enum-case-scope-lookup

Conversation

@Ronitsabhaya75
Copy link

This PR adds ScopeSyntax conformance to EnumCaseDeclSyntax so that name lookup actually works for enum case payloads.

Previously, associated-value parameter names were totally invisible to lookup. I just set it up so a parameter is only in scope for the default-value expressions of parameters that come after it in the same case. It doesn't leak into other cases (e.g. case foo(a: Int), bar(b: Int = a) won't resolve a) and isn't visible outside the enum case declaration at all.

I also added EnumCaseParameterSyntax: IdentifiableSyntax using the same logic as FunctionParameterSyntax, and threw in a few tests to cover the basic forward references and isolation behavior.

Let me know if this approach makes sense or if I should add more tests!

/// of subsequent parameters within the same case element, e.g.:
/// ```swift
/// enum E {
/// case foo(x: Int, y: Int = x) // `x` visible in `y`'s default
Copy link
Member

Choose a reason for hiding this comment

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

Is this true? As far as I tried, x is not visible from the default value of y. Am I missing anything?

Image

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