Skip to content

[SR-9761] Swift 5 migrator adds unnecessary type annotations #52189

Open
@keith

Description

@keith
Previous ID SR-9761
Radar None
Original Reporter @keith
Type Bug
Environment

Xcode 10.2 beta 2
Swift 4.2 -> Swift 5 migrator

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

md5: db350fb3d6f66b39b682595cf6f7a76d

Issue Description:

When running the migrator on this project https://github.com/lyft/mapper/ in Xcode 10.2 beta 1, it tries to migrate this:

public func optionalFrom<T>(_ field: String, transformation: (Any) throws -> T?) -> T? {
    return (try? transformation(try self.JSONFromField(field))).flatMap { $0 }
}

To this:

public func optionalFrom<T>(_ field: String, transformation: (Any) throws -> T?) -> T? {
    return (((try? transformation(try self.JSONFromField(field))) as T??)).flatMap { $0 }
}

The type of `JSONFromField` is:

func JSONFromField(_ field: String) throws -> Any

If I ignore this migration, and still move to Swift 5, it compiles fine. You should be able to reproduce this by cloning that repo, and migrating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfmigrator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions