swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
66.8k stars 10.29k forks source link

Non generic functions accept generic specialization syntax in some cases #73749

Open TeamPuzel opened 1 month ago

TeamPuzel commented 1 month ago

Description

Swift is allowing a syntax mistake.

Reproduction

It seems that a function can "accept" explicit generic parameters in this situation:

func z() -> Int { 1 }                 // Non generic function
func z<T: FloatingPoint>() -> T { 1 } // Generic overload of that function
let y: Int = z<Float>()               // Nonsense syntax compiles (the parameter is ignored but there is no error)

It does not seem to happen when either of the overloads is commented out, catching the invalid syntax.

Expected behavior

An error message detecting the misleading syntax.

Environment

Apple Swift version 6.0-dev (LLVM 3417addab6ff197, Swift d677b7c23fd6355)
Target: arm64-apple-macosx14.0

Additional information

No response

tbkka commented 1 month ago

CC: @slavapestov @xedin