Skip to content

[SR-1306] Inconsistent behavior with labeled type parameters #43914

@natecook1000

Description

@natecook1000
Previous ID SR-1306
Radar None
Original Reporter @natecook1000
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 2.2 and Swift 3 master branch

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

md5: 109c04a65b17188a6ae294c4a3e1ae14

duplicates:

  • SR-899 .self can be omitted if a function has only one parameter

Issue Description:

When a metatype type is used as a function parameter, whether or not the passed type requires ".self" depends on whether the parameter has an external label.

func foo<T>(type: T.Type) {
    print(T)
}

func bar<T>(baz type: T.Type) {
    print(T)
}

foo(String.self)        // ok
foo(String)             // ok
bar(baz: String.self)   // ok
bar(baz: String)        // error

The error output looks like this:

<REPL Input>:1:5: error: cannot create a single-element tuple with an element label
bar(baz: String)        // error
    ^~~~~
    
<REPL Input>:1:4: error: missing argument label 'baz:' in call
bar(baz: String)        // error
   ^
   baz: 

Whatever the correct behavior is should be consistent between foo(_:) and bar(baz:).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselftype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions