Skip to content
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

[SR-828] Overrides for default parameter values don't work as expected #43440

Closed
swift-ci opened this issue Feb 26, 2016 · 1 comment
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-828
Radar None
Original Reporter mkbrandt (JIRA User)
Type Bug
Status Resolved
Resolution Won't Do
Environment

Xcode 7.2.1

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

md5: 62322557f8f138fdf83c588e65ff7a46

Issue Description:

In one file I have:

class LineGraphic {
  func intersectionWithLine(g: LineGraphic, extended: Bool = false) {...}
}

In another I have:

class ConstructionLine: LineGraphic {
  func intersectionWithLine(g: LineGraphic, extended: Bool = true) {...}
}

When I call for an intersection on a ConstructionLine without an explicit extended parameter the value of extended is false instead of defaulting to true. In this instance I don't know if the line I am call intersection on is a regular line or a construction line.

I suspect that if I upcast the line to a construction line it will get the default value of extended right, but it seems like it should do so anyway. This is probably a result of this being a compiler generated default, rather than a runtime determined value, but the latter could be accomplished by creating two entry points for the actual function, one with the parameter and one without that assigns the correct default.

@belkadan
Copy link
Contributor

belkadan commented Mar 8, 2016

I think this is Won't Do, as we're moving towards having default arguments inlined into callers and that means we'd have to use the static type. If you really want this behavior, make the default argument call a method that the subclass can override.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants