Skip to content

[SR-4155] Generic argument deduction disabled in generic context #46738

@dabrahams

Description

@dabrahams
Previous ID SR-4155
Radar None
Original Reporter @dabrahams
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 2f198f51481b5b4892e90af8f01334c2

duplicates:

Issue Description:

This should work, but doesn't:

(swift) struct X<T> {
          init(_: T) {}
          func f() {
            print(X(3))
        }
        }
<REPL Input>:4:13: error: 'Int' is not convertible to 'T'
    print(X(3))
           ~^~
(swift)

The problem is that inside X, all mentions of X without explicit generic parameters are assumed to be Self, rather than only using that deduction as a last resort. It's very inconvenient in my particular use-case!

Metadata

Metadata

Assignees

No one assigned

    Labels

    TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfexpressionsFeature: expressionsgenericsFeature: generic declarations and typesswift 6.0swift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposaltype checkerArea → compiler: Semantic analysistype inferenceFeature: type inferenceunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions