Skip to content

Improve diagnostics for misspelt 'assocatedtype' #2180

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

Open
karwa opened this issue May 16, 2023 · 4 comments
Open

Improve diagnostics for misspelt 'assocatedtype' #2180

karwa opened this issue May 16, 2023 · 4 comments
Labels
SwiftParser Bugs in the (new) Parser written in Swift

Comments

@karwa
Copy link

karwa commented May 16, 2023

Description

Almost everything in Swift uses camelCase. A notable exception is associatedtype. If a user happens to write associatedType in a protocol declaration we currently provide rather poor diagnostics, assuming they meant to declare a function requirement. We should improve those diagnostics, pointing them to the recognised spelling.

Steps to reproduce

Welcome to Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100).
Type :help for assistance.
  1> protocol A { 
  2.     associatedType Foo 
  3. }
expression failed to parse:
error: error while processing module import: error: repl.swift:2:5: error: expected 'func' keyword in instance method declaration
    associatedType Foo
    ^
    func 

error: repl.swift:2:20: error: found an unexpected second identifier in function declaration; is there an accidental break?
    associatedType Foo
                   ^

repl.swift:2:20: note: join the identifiers together
    associatedType Foo
    ~~~~~~~~~~~~~~~^~~
    associatedTypeFoo

error: repl.swift:2:23: error: expected '(' in argument list of function declaration
    associatedType Foo
                      ^



fixed expression suggested:
  protocol A {
    associatedType Foo
}

Note that the suggested "fixed" expression does not correct the capitalisation.

Expected behavior

Expect we would notice that a user writing associatedType is clearly trying to write associatedtype, and direct them to the correct spelling.

Environment

  • Swift compiler version info
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
  • Xcode version info
Xcode 14.3
Build version 14E222b
@karwa karwa added the bug Something isn't working label May 16, 2023
@AnthonyLatsis AnthonyLatsis removed the bug Something isn't working label Sep 9, 2023
@AnthonyLatsis
Copy link
Contributor

@ahoppen Should we start transferring parser recovery issues like these to swift-syntax?

@ahoppen ahoppen transferred this issue from swiftlang/swift Sep 12, 2023
@ahoppen ahoppen added the SwiftParser Bugs in the (new) Parser written in Swift label Sep 12, 2023
@ahoppen
Copy link
Member

ahoppen commented Sep 12, 2023

Yes, we should track them in the swift-syntax repo + attach the SwiftParser keyword.

@ahoppen
Copy link
Member

ahoppen commented Sep 12, 2023

Tracked in Apple’s issue tracker as rdar://115385848

@AnthonyLatsis
Copy link
Contributor

AnthonyLatsis commented Sep 14, 2023

Yes, we should track them in the swift-syntax repo

Here are some more: #2196, #2204, #2198.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SwiftParser Bugs in the (new) Parser written in Swift
Projects
None yet
Development

No branches or pull requests

3 participants