Skip to content

[ParseableInterfaces] Find inherited default arg for initializer params #23933

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

Closed
wants to merge 1 commit into from

Conversation

harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Apr 10, 2019

Since we try not to synthesize inherited initializers, we want to be
explicit and print them in subclasses. Since the default argument kind
was Inherited, though, they would print as

override public init(value: Swift.Int = super)

...which doesn't parse.

Instead, try to walk up the override chain for these methods and pull
out the default argument string.

Fixes rdar://49789274

Since we try not to synthesize inherited initializers, we want to be
explicit and print them in subclasses. Since the default argument kind
was `Inherited`, though, they would print as

```
override public init(value: Swift.Int = super)
```

...which doesn't parse.

Instead, try to walk up the override chain for these methods and pull
out the default argument string.

Fixes rdar://49789274
@harlanhaskins harlanhaskins requested review from jrose-apple and nathawes and removed request for jrose-apple April 10, 2019 21:04
@slavapestov
Copy link
Contributor

slavapestov commented Apr 10, 2019

This is not correct, you really need a special syntax to round-trip the inherited default arg here because of generic substitutions.

For example try this:

public protocol Initable { init() }

public class Base<T : Initable> {
  public init(t: T = T()) {}
}

extension Array : Initable {}

public class Derived : Base<[Int]> {}

You're going to print the default argument as "T()", but there's no declaration named "T" that is visible from the derived class.

@jrose-apple
Copy link
Contributor

Yeah, we know. :-( But we don't have an alternative that doesn't require inventing new syntax for module interfaces. If you think this is a blocker, though, I guess we can do that.

@harlanhaskins
Copy link
Contributor Author

Thanks for catching that, @slavapestov! We still want to avoid inventing new syntax for things only in module interfaces, so I think the only way forward is to just omit these and leave them implicit in interfaces 😓

@slavapestov
Copy link
Contributor

what about an attribute on the ParamDecl?

init(@_inheritedDefaultValue t)

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.

3 participants