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

[SR-7903] Generic types with an associated type cannot be a default value in a func #50438

Open
bscothern opened this issue Jun 6, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@bscothern
Copy link

Previous ID SR-7903
Radar None
Original Reporter @bscothern
Type Bug
Environment

macOS 10.13.4

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 5e611b1b25ba8f020ac28556fcda7c4d

Issue Description:

The following code fails to compile

func foo<T: StringProtocol>(_ s: T = "Bar") {
    print(s)
}

foo()

Error Message

$ swiftc main.swift

main.swift:5:1: error: generic parameter 'T' could not be inferred
foo()
^
main.swift:1:6: note: in call to function 'foo'
func foo<T: StringProtocol>(_ s: T = "Bar") {

I get this error with these versions of swift:

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)
Target: x86_64-apple-darwin17.5.0

Apple Swift version 4.2-dev (LLVM a38ff55b31, Clang 5272858825, Swift defc3e9073)
Target: x86_64-apple-darwin17.5.0

Apple Swift version 4.2-dev (LLVM 031e148970, Clang b58a7ad218, Swift 0747546bd7)
Target: x86_64-apple-darwin17.5.0
@belkadan
Copy link
Contributor

belkadan commented Jun 6, 2018

I don't think this has anything to do with associated types. Since T conforms to StringProtocol, and StringProtocol inherits from ExpressibleByStringLiteral, I would expect this to work.

@bscothern
Copy link
Author

Good point

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants