Skip to content

Sema: Fudge backward compatibility for init special declname [4.2] #17229

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

Merged

Conversation

slavapestov
Copy link
Contributor

In Swift 4, constructors had the same name as properties,
methods and enum cases named init. This meant that you
could use constructor syntax to call such a member, which
caused some confusing behavior.

Recently I added a special declname for init so that
constructors have unique names distinct from any name you
can spell, and "foo.init" syntax would look for a member
with the special name rather than one named init.

Unfortunately people actually had code where they defined
members named init and then use them via normal member
lookup syntax, like this:

enum E {
  case `init`
}

let e: E = E.init

So to maintain backward compatibility, hack member lookup
to also find members named init when looking up the special
declname for constructors.

The workaround is only enabled in Swift 4 and 4.2 mode;
in Swift 5 mode you are expected to write "foo.init" to access
non-constructor members named init.

Fixes rdar://problem/38682258.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 84eed81aaa330e4d6e9a559587eaf35e3931a5c5

In Swift 4, constructors had the same name as properties,
methods and enum cases named `init`. This meant that you
could use constructor syntax to call such a member, which
caused some confusing behavior.

Recently I added a special declname for `init` so that
constructors have unique names distinct from any name you
can spell, and "foo.init" syntax would look for a member
with the special name rather than one named `init`.

Unfortunately people actually had code where they defined
members named `init` and then use them via normal member
lookup syntax, like this:

enum E {
  case `init`
}

let e: E = E.init

So to maintain backward compatibility, hack member lookup
to also find members named `init` when looking up the special
declname for constructors.

The workaround is only enabled in Swift 4 and 4.2 mode;
in Swift 5 mode you are expected to write "foo.`init`" to access
non-constructor members named `init`.

Fixes <rdar://problem/38682258>.
@slavapestov slavapestov force-pushed the init-declname-hack-4.2 branch from 84eed81 to 32119aa Compare June 15, 2018 04:31
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 88d04e7 into swiftlang:swift-4.2-branch Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants