Open
Description
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