Skip to content

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

@TeamPuzel

Description

@TeamPuzel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts invalidBug: Accepts invalidbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfexpressionsFeature: expressionsgenericsFeature: generic declarations and typesswift 6.0type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions