Skip to content

Sema: Fudge backward compatibility for init special declname #17227

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
merged 2 commits into from
Jun 15, 2018

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Jun 15, 2018

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 smoke test

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 smoke test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

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.

1 participant