swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.61k stars 10.37k forks source link

[SR-3623] Overloading a property name on an object should succeed if property types differ #46208

Open swift-ci opened 7 years ago

swift-ci commented 7 years ago
Previous ID SR-3623
Radar None
Original Reporter federman (JIRA User)
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, LanguageFeatureRequest | |Assignee | None | |Priority | Medium | md5: aafc357a03d201129bcb102591e19466

relates to:

Issue Description:

Expected results:
Property overloading should work as well as method overloading. Declaring two variables with the same name but different types on an object should work.

Actual results:
Property overloading fails with the error message: "Invalid redeclaration of '\<propertyName>'".

Reproducible test case:

struct ThingVendor {}
struct Cow {}
struct Spaceship {}

extension ThingVendor {
    var something: Cow {
        return Cow()
    }
}

extension ThingVendor {
    var something: Spaceship {
        return Spaceship()
    }
}

Note if you find/replace "var something:" with "func something() ->", the code compiles.

Environment: Xcode 8.2.1 (8C1002) – Swift 3

belkadan commented 7 years ago

This sort of change would have to go through the Swift Evolution Process.