Skip to content
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

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

Closed
TeamPuzel opened this issue May 20, 2024 · 5 comments
Closed
Labels
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself duplicate Resolution: Duplicates another issue expressions Feature: expressions generics Feature: generic declarations and types swift 6.0 type checker Area → compiler: Semantic analysis

Comments

@TeamPuzel
Copy link

TeamPuzel commented May 20, 2024

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

@TeamPuzel TeamPuzel added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels May 20, 2024
@tbkka
Copy link
Contributor

tbkka commented May 28, 2024

CC: @slavapestov @xedin

@hborla hborla added generics Feature: generic declarations and types and removed triage needed This issue needs more specific labels labels Jul 14, 2024
@xedin
Copy link
Contributor

xedin commented Aug 2, 2024

I think @gregomni fixed this recently via #75526

@xedin
Copy link
Contributor

xedin commented Aug 2, 2024

Main compiler produces:

3 | let y: Int = z<Float>()
  |              `- error: cannot specialize non-generic type '() -> Int'

@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself type checker Area → compiler: Semantic analysis accepts invalid Bug: Accepts invalid expressions Feature: expressions swift 6.0 labels Aug 2, 2024
@AnthonyLatsis
Copy link
Collaborator

Almost certainly. Bug still there in my June 4th checkout.

@AnthonyLatsis
Copy link
Collaborator

Duplicate of #74857

@AnthonyLatsis AnthonyLatsis marked this as a duplicate of #74857 Aug 2, 2024
@AnthonyLatsis AnthonyLatsis closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2024
@AnthonyLatsis AnthonyLatsis added the duplicate Resolution: Duplicates another issue label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts invalid Bug: Accepts invalid bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself duplicate Resolution: Duplicates another issue expressions Feature: expressions generics Feature: generic declarations and types swift 6.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

5 participants